LCOV - code coverage report
Current view: top level - src - zipinputstream.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 8 13 61.5 %
Date: 2024-06-15 08:26:09 Functions: 2 7 28.6 %
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-2022  Made to Order Software Corp.  All Rights Reserved
       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::ZipInputStream.
      24             :  *
      25             :  * This file includes the implementation of the zipios::ZipInputStream
      26             :  * class which is a filter used to read files from Zip archives, files
      27             :  * that can be compressed using the zlib library.
      28             :  */
      29             : 
      30             : #include "zipinputstream.hpp"
      31             : 
      32             : #include <fstream>
      33             : 
      34             : 
      35             : namespace zipios
      36             : {
      37             : 
      38             : 
      39             : /** \class ZipInputStream
      40             :  * \brief The ZipInputStream to read data from a Zip archive.
      41             :  *
      42             :  * ZipInputStream is an istream that gets its input from a zip file. The
      43             :  * interface was redesigned in version 2.x to be more C++ like.
      44             :  *
      45             :  * \note
      46             :  * The getNextEntry() was removed because we cannot make it work here.
      47             :  * The old implementation would let someone read all the local directory
      48             :  * entries one after another. Only that is not correct and since this class
      49             :  * is not publicly exposed anymore, it wouldn't be available anyway.
      50             :  */
      51             : 
      52             : 
      53             : /** \brief Initialize a ZipInputStream from a filename and position.
      54             :  *
      55             :  * This constructor creates a ZIP file stream by attaching itself to
      56             :  * a file as defined by the specified filename and a position to the
      57             :  * header of the file being read.
      58             :  *
      59             :  * \param[in] filename  The name of a valid zip file.
      60             :  * \param[in] pos position to reposition the istream to before reading.
      61             :  */
      62       53061 : ZipInputStream::ZipInputStream(std::string const & filename, std::streampos pos)
      63             :     : std::istream(nullptr)
      64       53061 :     , m_ifs(std::make_unique<std::ifstream>(filename, std::ios::in | std::ios::binary))
      65       53061 :     , m_ifs_ref(*m_ifs)
      66      106122 :     , m_izf(std::make_unique<ZipInputStreambuf>(m_ifs_ref.rdbuf(), pos))
      67             : {
      68             :     // properly initialize the stream with the newly allocated buffer
      69       53041 :     init(m_izf.get());
      70       53101 : }
      71             : 
      72             : 
      73           0 : ZipInputStream::ZipInputStream(std::istream & is)
      74             :     : std::istream(nullptr)
      75           0 :     , m_ifs_ref(is)
      76           0 :     , m_izf(std::make_unique<ZipInputStreambuf>(m_ifs_ref.rdbuf(), 0))
      77             : {
      78             :     // properly initialize the stream with the newly allocated buffer
      79           0 :     init(m_izf.get());
      80           0 : }
      81             : 
      82             : 
      83             : /** \brief Clean up the input stream.
      84             :  *
      85             :  * The destructor ensures that all resources used by the class get
      86             :  * released.
      87             :  */
      88       53041 : ZipInputStream::~ZipInputStream()
      89             : {
      90       53041 : }
      91             : 
      92             : 
      93             : } // zipios namespace
      94             : 
      95             : // Local Variables:
      96             : // mode: cpp
      97             : // indent-tabs-mode: nil
      98             : // c-basic-offset: 4
      99             : // tab-width: 4
     100             : // End:
     101             : 
     102             : // vim: ts=4 sw=4 et

Generated by: LCOV version 1.14

Snap C++ | List of projects | List of versions