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

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

Issue 2807063002: Replace Libarchive with MiniZip. (Closed)
Patch Set: Fix a few nits. 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
18 const int kFilePermission = 640; 19 const char kCreateArchiveError[] = "Failed to create archive.";
19 const int kDirectoryPermission = 760; 20 const char kAddToArchiveError[] = "Failed to add entry to archive.";
20 } // namespace compressor_archive_constants 21 const char kCloseArchiveError[] = "Failed to close archive.";
22
23 }
24
25 // A name space with custom functions passed to minizip.
26 namespace compressor_archive_functions {
27
28 uLong CustomArchiveWrite(void* compressor,
29 void* stream,
30 const void* buffer,
31 uLong length);
32
33 long CustomArchiveTell(void* compressor, void* stream);
34
35 long CustomArchiveSeek(void* compressor,
36 void* stream,
37 uLong offset,
38 int origin);
39
40 } // compressor_archive_functions
21 41
22 class CompressorArchiveLibarchive : public CompressorArchive { 42 class CompressorArchiveLibarchive : public CompressorArchive {
23 public: 43 public:
24 explicit CompressorArchiveLibarchive(CompressorStream* compressor_stream); 44 explicit CompressorArchiveLibarchive(CompressorStream* compressor_stream);
25 45
26 virtual ~CompressorArchiveLibarchive(); 46 virtual ~CompressorArchiveLibarchive();
27 47
28 // Creates an archive object. 48 // Creates an archive object.
29 virtual void CreateArchive(); 49 virtual bool CreateArchive();
30 50
31 // Releases all resources obtained by libarchive. 51 // Releases all resources obtained by libarchive.
32 virtual void CloseArchive(bool has_error); 52 virtual bool CloseArchive(bool has_error);
33 53
34 // Adds an entry to the archive. 54 // Adds an entry to the archive.
35 virtual void AddToArchive(const std::string& filename, 55 virtual bool AddToArchive(const std::string& filename,
36 int64_t file_size, 56 int64_t file_size,
37 time_t modification_time, 57 int64_t modification_time,
38 bool is_directory); 58 bool is_directory);
39 59
40 // A getter function for archive_. 60 // A getter function for zip_file_.
41 struct archive* archive() const { return archive_; } 61 zipFile zip_file() const { return zip_file_; }
42 62
43 // A getter function for compressor_stream. 63 // A getter function for compressor_stream.
44 CompressorStream* compressor_stream() const { return compressor_stream_; } 64 CompressorStream* compressor_stream() const { return compressor_stream_; }
45 65
66 // Custom functions need to access private variables of
67 // CompressorArchiveLibarchive frequently.
68 friend uLong compressor_archive_functions::CustomArchiveWrite(
69 void* compressor, void* stream, const void* buffer, uLong length);
70
71 friend long compressor_archive_functions::CustomArchiveTell(
72 void* compressor, void* stream);
73
74 friend long compressor_archive_functions::CustomArchiveSeek(
75 void* compressor, void* stream, uLong offset, int origin);
76
46 private: 77 private:
47 // An instance that takes care of all IO operations. 78 // An instance that takes care of all IO operations.
48 CompressorStream* compressor_stream_; 79 CompressorStream* compressor_stream_;
49 80
50 // The libarchive correspondent archive object. 81 // The minizip correspondent archive object.
51 struct archive* archive_; 82 zipFile zip_file_;
52
53 // The libarchive correspondent archive entry object that is currently
54 // processed.
55 struct archive_entry* entry;
56 83
57 // The buffer used to store the data read from JavaScript. 84 // The buffer used to store the data read from JavaScript.
58 char* destination_buffer_; 85 char* destination_buffer_;
86
87 // The current offset of the zip archive file.
88 int64_t offset_;
89 // The size of the zip archive file.
90 int64_t length_;
59 }; 91 };
60 92
61 #endif // COMPRESSOR_ARCHIVE_LIBARCHIVE_H_ 93 #endif // COMPRESSOR_ARCHIVE_LIBARCHIVE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698