LCOV - code coverage report
Current view: top level - src - gzipoutputstream.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 26 3.8 %
Date: 2019-04-24 14:10:30 Functions: 2 13 15.4 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :   Zipios -- a small C++ library that provides easy access to .zip files.
       3             : 
       4             :   Copyright (C) 2000-2007  Thomas Sondergaard
       5             :   Copyright (C) 2015-2019  Made to Order Software Corporation
       6             : 
       7             :   This library is free software; you can redistribute it and/or
       8             :   modify it under the terms of the GNU Lesser General Public
       9             :   License as published by the Free Software Foundation; either
      10             :   version 2.1 of the License, or (at your option) any later version.
      11             : 
      12             :   This library is distributed in the hope that it will be useful,
      13             :   but WITHOUT ANY WARRANTY; without even the implied warranty of
      14             :   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      15             :   Lesser General Public License for more details.
      16             : 
      17             :   You should have received a copy of the GNU Lesser General Public
      18             :   License along with this library; if not, write to the Free Software
      19             :   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
      20             : */
      21             : 
      22             : /** \file
      23             :  * \brief Implementation of zipios::GZIPOutputStream.
      24             :  *
      25             :  * The zipios::GZipOutputStream defines functions which handle the
      26             :  * saving of Zip archive content file in compressed form using
      27             :  * the zlib library.
      28             :  */
      29             : 
      30             : #include "gzipoutputstream.hpp"
      31             : 
      32             : #include <fstream>
      33             : 
      34             : 
      35             : namespace zipios
      36             : {
      37             : 
      38             : /** \class GZIPOutputStream
      39             :  * \brief A stream implementation that outputs data to a ZIP file.
      40             :  *
      41             :  * GZIPOutputStream is an ostream that writes the output to a zip file.
      42             :  * The interface approximates the interface of the Java GZIPOutputStream.
      43             :  *
      44             :  * It can be used with either an existing std::ostream object, or
      45             :  * a filename.
      46             :  */
      47             : 
      48             : 
      49             : 
      50             : /** \brief Create a ZIP output stream object.
      51             :  *
      52             :  * This constructor creates a zip stream from an existing standard
      53             :  * output stream.
      54             :  *
      55             :  * \warning
      56             :  * You must keep the output stream valid for as long as this object
      57             :  * exists (although this object close() function can be used to close
      58             :  * the \p os stream.)
      59             :  *
      60             :  * \param[in,out] os  ostream to which the compressed zip archive is written.
      61             :  * \param[in] compression_level  The compression level to use to compress.
      62             :  */
      63           0 : GZIPOutputStream::GZIPOutputStream(std::ostream& os, FileEntry::CompressionLevel compression_level)
      64             :     //: std::ostream() -- auto-init
      65             :     //, m_ofs(nullptr) -- auto-init
      66           0 :     : m_ozf(new GZIPOutputStreambuf(os.rdbuf(), compression_level))
      67             : {
      68           0 :     init(m_ozf.get());
      69           0 : }
      70             : 
      71             : 
      72             : /** \brief Create a named ZIP stream for output.
      73             :  *
      74             :  * \note
      75             :  * The fielname is not automatically saved as part of the stream.
      76             :  * To do so, call the setFilename() function.
      77             :  *
      78             :  * \param[in] filename  Name of the file where the zip archive is to
      79             :  *                      be written.
      80             :  * \param[in] compression_level  The compression level to use to compress.
      81             :  */
      82           0 : GZIPOutputStream::GZIPOutputStream(std::string const& filename, FileEntry::CompressionLevel compression_level)
      83             :     : std::ostream(0)
      84           0 :     , m_ofs(new std::ofstream(filename.c_str(), std::ios::out | std::ios::binary))
      85           0 :     , m_ozf(new GZIPOutputStreambuf(m_ofs->rdbuf(), compression_level))
      86             : {
      87           0 :     init(m_ozf.get());
      88           0 : }
      89             : 
      90             : 
      91             : /** \brief Destroy the output stream.
      92             :  *
      93             :  * The destructor ensures that all allocated resources get destroyed.
      94             :  */
      95           0 : GZIPOutputStream::~GZIPOutputStream()
      96             : {
      97           0 : }
      98             : 
      99             : 
     100             : /** \brief Set the filename of a stream.
     101             :  *
     102             :  * This function can be used to set the name of the file being
     103             :  * added to this stream.
     104             :  *
     105             :  * The filename is optional.
     106             :  *
     107             :  * \param[in] filename  The filename to attach to this stream.
     108             :  */
     109           0 : void GZIPOutputStream::setFilename(std::string const& filename)
     110             : {
     111           0 :     m_ozf->setFilename(filename);
     112           0 : }
     113             : 
     114             : 
     115             : /** \brief Set a comment in the stream.
     116             :  *
     117             :  * This function can be used to add a comment to the zip file.
     118             :  *
     119             :  * A comment is optional.
     120             :  *
     121             :  * \param[in] comment  The comment to attach to this stream.
     122             :  */
     123           0 : void GZIPOutputStream::setComment(std::string const& comment)
     124             : {
     125           0 :     m_ozf->setComment(comment);
     126           0 : }
     127             : 
     128             : 
     129             : /** \brief Close the streams.
     130             :  *
     131             :  * This function closes the streams making sure that all data gets
     132             :  * saved in the output file.
     133             :  *
     134             :  * It is not required since destroying the object will also force
     135             :  * a close.
     136             :  */
     137           0 : void GZIPOutputStream::close()
     138             : {
     139           0 :     m_ozf->close();
     140           0 :     if(m_ofs)
     141             :     {
     142           0 :         m_ofs->close();
     143             :     }
     144           0 : }
     145             : 
     146             : 
     147             : /** \brief Finishes the stream.
     148             :  *
     149             :  */
     150           0 : void GZIPOutputStream::finish()
     151             : {
     152           0 :     m_ozf->finish();
     153           0 : }
     154             : 
     155             : 
     156           3 : } // zipios namespace
     157             : 
     158             : // Local Variables:
     159             : // mode: cpp
     160             : // indent-tabs-mode: nil
     161             : // c-basic-offset: 4
     162             : // tab-width: 4
     163             : // End:
     164             : 
     165             : // vim: ts=4 sw=4 et

Generated by: LCOV version 1.12