1414
1515namespace odr ::internal::zip {
1616
17- ZipArchive::Entry::Entry (Path path, std::shared_ptr<abstract::File> file,
17+ ZipArchive::Entry::Entry (RelPath path, std::shared_ptr<abstract::File> file,
1818 std::uint32_t compression_level)
1919 : m_path{std::move (path)}, m_file{std::move (file)},
2020 m_compression_level{compression_level} {}
2121
22- bool ZipArchive::Entry::is_file () const { return m_file. operator bool () ; }
22+ bool ZipArchive::Entry::is_file () const { return m_file != nullptr ; }
2323
24- bool ZipArchive::Entry::is_directory () const { return ! m_file; }
24+ bool ZipArchive::Entry::is_directory () const { return m_file == nullptr ; }
2525
26- Path ZipArchive::Entry::path () const { return m_path; }
26+ const RelPath & ZipArchive::Entry::path () const { return m_path; }
2727
2828std::shared_ptr<abstract::File> ZipArchive::Entry::file () const {
2929 return m_file;
@@ -41,14 +41,15 @@ ZipArchive::ZipArchive() = default;
4141
4242ZipArchive::ZipArchive (const std::shared_ptr<util::Archive> &archive) {
4343 for (auto &&entry : *archive) {
44+ RelPath path (entry.path ());
4445 if (entry.is_file ()) {
4546 std::uint8_t compression_level = 6 ;
4647 if (entry.method () == util::Method::STORED ) {
4748 compression_level = 0 ;
4849 }
49- insert_file (end (), entry. path ( ), entry.file (), compression_level);
50+ insert_file (end (), std::move (path ), entry.file (), compression_level);
5051 } else if (entry.is_directory ()) {
51- insert_directory (end (), entry. path ( ));
52+ insert_directory (end (), std::move (path ));
5253 }
5354 }
5455}
@@ -58,7 +59,7 @@ std::shared_ptr<abstract::Filesystem> ZipArchive::as_filesystem() const {
5859 auto filesystem = std::make_shared<VirtualFilesystem>();
5960
6061 for (const auto &e : *this ) {
61- AbsPath path = e.path ().make_absolute ();
62+ AbsPath path = Path ( e.path () ).make_absolute ();
6263
6364 if (e.is_directory ()) {
6465 filesystem->create_directory (path);
@@ -80,7 +81,8 @@ void ZipArchive::save(std::ostream &out) const {
8081 archive.m_pWrite = [](void *opaque, std::uint64_t /* offset*/ ,
8182 const void *buffer, std::size_t size) {
8283 auto out = static_cast <std::ostream *>(opaque);
83- out->write (static_cast <const char *>(buffer), size);
84+ out->write (static_cast <const char *>(buffer),
85+ static_cast <std::streamsize>(size));
8486 return size;
8587 };
8688 state = mz_zip_writer_init (&archive, 0 );
@@ -89,7 +91,7 @@ void ZipArchive::save(std::ostream &out) const {
8991 }
9092
9193 for (auto &&entry : *this ) {
92- auto path = entry.path ().make_absolute ();
94+ RelPath path = entry.path ().make_relative ();
9395
9496 if (entry.is_file ()) {
9597 auto file = entry.file ();
@@ -128,7 +130,7 @@ ZipArchive::Iterator ZipArchive::begin() const {
128130
129131ZipArchive::Iterator ZipArchive::end () const { return std::cend (m_entries); }
130132
131- ZipArchive::Iterator ZipArchive::find (const Path &path) const {
133+ ZipArchive::Iterator ZipArchive::find (const RelPath &path) const {
132134 for (auto it = begin (); it != end (); ++it) {
133135 if (it->path () == path) {
134136 return it;
@@ -139,15 +141,15 @@ ZipArchive::Iterator ZipArchive::find(const Path &path) const {
139141}
140142
141143ZipArchive::Iterator
142- ZipArchive::insert_file (Iterator at, Path path,
144+ ZipArchive::insert_file (Iterator at, RelPath path,
143145 std::shared_ptr<abstract::File> file,
144146 std::uint32_t compression_level) {
145147 return m_entries.insert (
146148 at,
147149 ZipArchive::Entry (std::move (path), std::move (file), compression_level));
148150}
149151
150- ZipArchive::Iterator ZipArchive::insert_directory (Iterator at, Path path) {
152+ ZipArchive::Iterator ZipArchive::insert_directory (Iterator at, RelPath path) {
151153 return m_entries.insert (at, ZipArchive::Entry (std::move (path), nullptr , 0 ));
152154}
153155
0 commit comments