fw4spl
ReadDirArchive.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2016.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #include <boost/filesystem/path.hpp>
8 #include <boost/filesystem/operations.hpp>
9 
10 #include <fwCore/exceptionmacros.hpp>
11 
12 #include "minizip/unzip.h"
13 #include "fwZip/ReadDirArchive.hpp"
14 #include "fwZip/exception/Read.hpp"
15 
16 namespace fwZip
17 {
18 
19 //-----------------------------------------------------------------------------
20 
21 ReadDirArchive::ReadDirArchive( const ::boost::filesystem::path &archive ) :
22  m_archive(archive)
23 {
24 }
25 
26 //-----------------------------------------------------------------------------
27 
29 {
30 }
31 
32 //-----------------------------------------------------------------------------
33 
34 SPTR(std::istream) ReadDirArchive::getFile(const ::boost::filesystem::path &path)
35 {
36  FW_RAISE_EXCEPTION_IF(
37  ::fwZip::exception::Read("File '" + path.string() + "' "
38  "in archive '" + m_archive.string() + "' doesn't exist."),
39  !::boost::filesystem::exists(m_archive / path));
40 
41  SPTR(std::ifstream) is = std::make_shared< std::ifstream >();
42  is->open((m_archive / path).string().c_str(), std::fstream::binary | std::fstream::in);
43  return is;
44 }
45 
46 //-----------------------------------------------------------------------------
47 
48 const ::boost::filesystem::path ReadDirArchive::getArchivePath() const
49 {
50  return m_archive;
51 }
52 
53 }
54 
#define SPTR(_cls_)
Read exception.
Definition: Read.hpp:21
FWZIP_APIconst::boost::filesystem::path getArchivePath() const override
Returns archive path.
FWZIP_API std::shared_ptr< std::istream > getFile(const ::boost::filesystem::path &path) override
Returns input stream for the file in current archive.
FWZIP_API ReadDirArchive(const ::boost::filesystem::path &archive)
Constructors. Initializes archive path.
The namespace fwZip provides IO for compress/uncompress .zip files using zlib .
Definition: Read.hpp:14
FWZIP_API ~ReadDirArchive()
Destructor. Close automatically last input file stream.
This class defines functions to read a file in a file system archive.