7 #include "fwZip/ReadZipArchive.hpp" 9 #include "fwZip/exception/Read.hpp" 11 #include "minizip/unzip.h" 13 #include <fwCore/exceptionmacros.hpp> 15 #include <boost/filesystem/operations.hpp> 16 #include <boost/filesystem/path.hpp> 17 #include <boost/iostreams/categories.hpp> 18 #include <boost/iostreams/stream.hpp> 27 void* openReadZipArchive( const ::boost::filesystem::path& archive )
29 FW_RAISE_EXCEPTION_IF(
31 !::boost::filesystem::exists(archive));
33 void* zip = unzOpen(archive.string().c_str());
35 FW_RAISE_EXCEPTION_IF(
47 typedef char char_type;
48 typedef ::boost::iostreams::source_tag category;
50 ZipSource( const ::boost::filesystem::path& archive) :
51 m_zipDescriptor( openReadZipArchive(archive), &unzClose ),
57 ZipSource( const ::boost::filesystem::path& archive, const ::boost::filesystem::path& path ) :
58 m_zipDescriptor( openReadZipArchive(archive), &unzClose ),
62 int nRet = unzLocateFile(m_zipDescriptor.get(), path.string().c_str(), 0);
64 FW_RAISE_EXCEPTION_IF(
66 archive.string() +
"' doesn't exist."),
69 nRet = unzOpenCurrentFile(m_zipDescriptor.get());
70 FW_RAISE_EXCEPTION_IF(
72 "' in archive '"+ archive.string() +
"'."),
78 std::streamsize read(
char* s, std::streamsize n)
80 std::streamsize nRet = unzReadCurrentFile(m_zipDescriptor.get(), s,
static_cast< unsigned int >(n));
81 FW_RAISE_EXCEPTION_IF(
83 +
":" + m_path.string() +
"'."),
90 std::string getComment()
94 std::streamsize nRet = unzGetGlobalInfo(m_zipDescriptor.get(), info);
96 FW_RAISE_EXCEPTION_IF(
98 m_archive.string() +
"'."),
101 char* comment =
new char[info->size_comment];
102 nRet = unzGetGlobalComment(m_zipDescriptor.get(), comment, info->size_comment);
104 FW_RAISE_EXCEPTION_IF(
106 m_archive.string() +
"'."),
109 std::string stringComment(comment, info->size_comment);
114 return stringComment;
118 SPTR(
void) m_zipDescriptor;
119 ::boost::filesystem::path m_archive;
120 ::boost::filesystem::path m_path;
125 ReadZipArchive::ReadZipArchive( const ::boost::filesystem::path& archive ) :
134 SPTR(::boost::iostreams::stream<ZipSource>) is
135 = std::make_shared< ::boost::iostreams::stream<ZipSource> >(m_archive, path);
144 SPTR(
ZipSource) zip = std::make_shared<ZipSource>(m_archive);
146 return zip->getComment();
This class defines functions to read a file in a zip archive.
The namespace fwZip provides IO for compress/uncompress .zip files using zlib .
FWZIP_API std::string getComment()
Returns comment from the current archive (zip).
FWZIP_APIconst::boost::filesystem::path getArchivePath() const override
Returns archive path.