7 #include "fwZip/exception/Write.hpp" 9 #include "minizip/zip.h" 10 #include "fwZip/WriteDirArchive.hpp" 12 #include <fwCore/exceptionmacros.hpp> 17 #include <boost/filesystem/path.hpp> 18 #include <boost/filesystem/operations.hpp> 20 #include <boost/iostreams/stream_buffer.hpp> 31 if(!::boost::filesystem::exists(m_archive))
33 ::boost::filesystem::create_directories(m_archive);
47 const ::boost::filesystem::path file = m_archive / path;
48 const ::boost::filesystem::path parentFile = file.parent_path();
49 if(!::boost::filesystem::exists(parentFile))
51 ::boost::filesystem::create_directories(parentFile);
54 SPTR(std::ofstream) os = std::make_shared< std::ofstream >();
55 os->open(file.string().c_str(), std::fstream::binary | std::fstream::out | std::fstream::trunc);
62 const ::boost::filesystem::path &destinationFile)
64 const ::boost::filesystem::path fileDest = m_archive / destinationFile;
65 if (!::boost::filesystem::exists(fileDest))
67 const ::boost::filesystem::path parentFile = fileDest.parent_path();
68 if(!::boost::filesystem::exists(parentFile))
70 ::boost::filesystem::create_directories(parentFile);
72 ::boost::system::error_code err;
73 ::boost::filesystem::create_hard_link( sourceFile, fileDest, err );
79 std::string strSource = sourceFile.string();
80 std::string strDest = fileDest.string();
81 std::ifstream src(strSource.c_str(), std::ios::binary);
82 std::ofstream dst(strDest.c_str(), std::ios::binary);
94 return ::boost::filesystem::create_directories(m_archive/path);
This class defines functions to write a file in a file system archive.
FWZIP_API bool createDir(const ::boost::filesystem::path &path) override
Creates a folder in archive.
FWZIP_API std::shared_ptr< std::ostream > createFile(const ::boost::filesystem::path &path) override
Creates a new file entry in archive and returns output stream for this file.
FWZIP_API void putFile(const ::boost::filesystem::path &sourceFile, const ::boost::filesystem::path &destinationFile) override
Writes source file in archive. If possible, creates hard link otherwise copy source file in archive...
FWZIP_APIconst::boost::filesystem::path getArchivePath() const override
Returns archive path.
FWZIP_API ~WriteDirArchive()
Destructor. Flush and close last output file stream.
The namespace fwZip provides IO for compress/uncompress .zip files using zlib .
FWZIP_API WriteDirArchive(const ::boost::filesystem::path &archive)
Constructors. Initializes archive path and creates archive directories if doesn't exist...