 Chromium Code Reviews
 Chromium Code Reviews Issue 2807063002:
  Replace Libarchive with MiniZip.  (Closed)
    
  
    Issue 2807063002:
  Replace Libarchive with MiniZip.  (Closed) 
  | Index: ui/file_manager/zip_archiver/cpp/compressor_archive_libarchive.h | 
| diff --git a/ui/file_manager/zip_archiver/cpp/compressor_archive_libarchive.h b/ui/file_manager/zip_archiver/cpp/compressor_archive_libarchive.h | 
| index b0a299da65f31e155deeff76177a8cbdb242132c..a991ee5e77d105ecb144055a40507305c3b0a77c 100644 | 
| --- a/ui/file_manager/zip_archiver/cpp/compressor_archive_libarchive.h | 
| +++ b/ui/file_manager/zip_archiver/cpp/compressor_archive_libarchive.h | 
| @@ -7,17 +7,32 @@ | 
| #include <string> | 
| -#include "archive.h" | 
| +#include "third_party/zlib/contrib/minizip/unzip.h" | 
| +#include "third_party/zlib/contrib/minizip/zip.h" | 
| #include "compressor_archive.h" | 
| #include "compressor_stream.h" | 
| // A namespace with constants used by CompressorArchiveLibarchive. | 
| namespace compressor_archive_constants { | 
| -const int64_t kMaximumDataChunkSize = 512 * 1024; | 
| -const int kFilePermission = 640; | 
| -const int kDirectoryPermission = 760; | 
| -} // namespace compressor_archive_constants | 
| +const char kCreateArchiveError[] = "Failed to create archive."; | 
| +const char kAddtoArchiveError[] = "Failed to add entry to archive."; | 
| 
mtomasz
2017/04/10 07:15:08
nit: Addto -> AddTo ?
 
takise
2017/04/11 06:00:51
Done.
 | 
| +const char kCloseArchiveError[] = "Failed to close archive."; | 
| +} | 
| + | 
| +// A name space with custom functions passed to minizip. | 
| +namespace compressor_archive_functions { | 
| + uLong CustomArchiveWrite(void* opaque, | 
| + void* /*stream*/, | 
| + const void* buffer, | 
| + uLong length); | 
| + long CustomArchiveTell(void* opaque, void* /*stream*/); | 
| + long CustomArchiveSeek(void* opaque, | 
| + void* /*stream*/, | 
| + uLong offset, | 
| + int origin); | 
| + | 
| +} // compressor_archive_functions | 
| 
mtomasz
2017/04/10 07:15:08
nit: \s\s before //
 
takise
2017/04/11 06:00:51
Done.
 | 
| class CompressorArchiveLibarchive : public CompressorArchive { | 
| 
mtomasz
2017/04/10 07:15:08
nit: Libarchive -> MiniZip?
 | 
| public: | 
| @@ -26,36 +41,46 @@ class CompressorArchiveLibarchive : public CompressorArchive { | 
| virtual ~CompressorArchiveLibarchive(); | 
| // Creates an archive object. | 
| - virtual void CreateArchive(); | 
| + virtual bool CreateArchive(); | 
| // Releases all resources obtained by libarchive. | 
| - virtual void CloseArchive(bool has_error); | 
| + virtual bool CloseArchive(bool has_error); | 
| // Adds an entry to the archive. | 
| - virtual void AddToArchive(const std::string& filename, | 
| + virtual bool AddToArchive(const std::string& filename, | 
| int64_t file_size, | 
| - time_t modification_time, | 
| + int64_t modification_time, | 
| bool is_directory); | 
| - // A getter function for archive_. | 
| - struct archive* archive() const { return archive_; } | 
| + // A getter function for zip_file_. | 
| + zipFile zip_file() const { return zip_file_; } | 
| // A getter function for compressor_stream. | 
| CompressorStream* compressor_stream() const { return compressor_stream_; } | 
| + // Custom functions need to access private variables of | 
| + // CompressorArchiveLibarchive frequently. | 
| + friend uLong compressor_archive_functions::CustomArchiveWrite( | 
| + void* opaque, void* /*stream*/, const void* buffer, uLong length); | 
| + friend long compressor_archive_functions::CustomArchiveTell( | 
| + void* opaque, void* /*stream*/); | 
| + friend long compressor_archive_functions::CustomArchiveSeek( | 
| + void* opaque, void* /*stream*/, uLong offset, int origin); | 
| + | 
| private: | 
| // An instance that takes care of all IO operations. | 
| CompressorStream* compressor_stream_; | 
| - // The libarchive correspondent archive object. | 
| - struct archive* archive_; | 
| - | 
| - // The libarchive correspondent archive entry object that is currently | 
| - // processed. | 
| - struct archive_entry* entry; | 
| + // The minizip correspondent archive object. | 
| + zipFile zip_file_; | 
| // The buffer used to store the data read from JavaScript. | 
| char* destination_buffer_; | 
| + | 
| + // The current offset of the zip archive file. | 
| + int64_t offset_; | 
| + // The size of the zip archive file. | 
| + int64_t length_; | 
| }; | 
| #endif // COMPRESSOR_ARCHIVE_LIBARCHIVE_H_ |