Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Side by Side Diff: ui/file_manager/zip_archiver/cpp/compressor_archive_libarchive.h

Issue 2807063002: Replace Libarchive with MiniZip. (Closed)
Patch Set: Delete BUILD.gn Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium OS Authors. All rights reserved. 1 // Copyright 2017 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPRESSOR_ARCHIVE_LIBARCHIVE_H_ 5 #ifndef COMPRESSOR_ARCHIVE_LIBARCHIVE_H_
6 #define COMPRESSOR_ARCHIVE_LIBARCHIVE_H_ 6 #define COMPRESSOR_ARCHIVE_LIBARCHIVE_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "archive.h" 10 #include "third_party/zlib/contrib/minizip/unzip.h"
11 #include "third_party/zlib/contrib/minizip/zip.h"
11 12
12 #include "compressor_archive.h" 13 #include "compressor_archive.h"
13 #include "compressor_stream.h" 14 #include "compressor_stream.h"
14 15
15 // A namespace with constants used by CompressorArchiveLibarchive. 16 // A namespace with constants used by CompressorArchiveLibarchive.
16 namespace compressor_archive_constants { 17 namespace compressor_archive_constants {
17 const int64_t kMaximumDataChunkSize = 512 * 1024; 18 const char kCreateArchiveError[] = "Failed to create archive.";
18 const int kFilePermission = 640; 19 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.
19 const int kDirectoryPermission = 760; 20 const char kCloseArchiveError[] = "Failed to close archive.";
20 } // namespace compressor_archive_constants 21 }
22
23 // A name space with custom functions passed to minizip.
24 namespace compressor_archive_functions {
25 uLong CustomArchiveWrite(void* opaque,
26 void* /*stream*/,
27 const void* buffer,
28 uLong length);
29 long CustomArchiveTell(void* opaque, void* /*stream*/);
30 long CustomArchiveSeek(void* opaque,
31 void* /*stream*/,
32 uLong offset,
33 int origin);
34
35 } // compressor_archive_functions
mtomasz 2017/04/10 07:15:08 nit: \s\s before //
takise 2017/04/11 06:00:51 Done.
21 36
22 class CompressorArchiveLibarchive : public CompressorArchive { 37 class CompressorArchiveLibarchive : public CompressorArchive {
mtomasz 2017/04/10 07:15:08 nit: Libarchive -> MiniZip?
23 public: 38 public:
24 explicit CompressorArchiveLibarchive(CompressorStream* compressor_stream); 39 explicit CompressorArchiveLibarchive(CompressorStream* compressor_stream);
25 40
26 virtual ~CompressorArchiveLibarchive(); 41 virtual ~CompressorArchiveLibarchive();
27 42
28 // Creates an archive object. 43 // Creates an archive object.
29 virtual void CreateArchive(); 44 virtual bool CreateArchive();
30 45
31 // Releases all resources obtained by libarchive. 46 // Releases all resources obtained by libarchive.
32 virtual void CloseArchive(bool has_error); 47 virtual bool CloseArchive(bool has_error);
33 48
34 // Adds an entry to the archive. 49 // Adds an entry to the archive.
35 virtual void AddToArchive(const std::string& filename, 50 virtual bool AddToArchive(const std::string& filename,
36 int64_t file_size, 51 int64_t file_size,
37 time_t modification_time, 52 int64_t modification_time,
38 bool is_directory); 53 bool is_directory);
39 54
40 // A getter function for archive_. 55 // A getter function for zip_file_.
41 struct archive* archive() const { return archive_; } 56 zipFile zip_file() const { return zip_file_; }
42 57
43 // A getter function for compressor_stream. 58 // A getter function for compressor_stream.
44 CompressorStream* compressor_stream() const { return compressor_stream_; } 59 CompressorStream* compressor_stream() const { return compressor_stream_; }
45 60
61 // Custom functions need to access private variables of
62 // CompressorArchiveLibarchive frequently.
63 friend uLong compressor_archive_functions::CustomArchiveWrite(
64 void* opaque, void* /*stream*/, const void* buffer, uLong length);
65 friend long compressor_archive_functions::CustomArchiveTell(
66 void* opaque, void* /*stream*/);
67 friend long compressor_archive_functions::CustomArchiveSeek(
68 void* opaque, void* /*stream*/, uLong offset, int origin);
69
46 private: 70 private:
47 // An instance that takes care of all IO operations. 71 // An instance that takes care of all IO operations.
48 CompressorStream* compressor_stream_; 72 CompressorStream* compressor_stream_;
49 73
50 // The libarchive correspondent archive object. 74 // The minizip correspondent archive object.
51 struct archive* archive_; 75 zipFile zip_file_;
52
53 // The libarchive correspondent archive entry object that is currently
54 // processed.
55 struct archive_entry* entry;
56 76
57 // The buffer used to store the data read from JavaScript. 77 // The buffer used to store the data read from JavaScript.
58 char* destination_buffer_; 78 char* destination_buffer_;
79
80 // The current offset of the zip archive file.
81 int64_t offset_;
82 // The size of the zip archive file.
83 int64_t length_;
59 }; 84 };
60 85
61 #endif // COMPRESSOR_ARCHIVE_LIBARCHIVE_H_ 86 #endif // COMPRESSOR_ARCHIVE_LIBARCHIVE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698