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

Side by Side Diff: ui/file_manager/zip_archiver/cpp/compressor_archive.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 COMPRESSSOR_ARCHIVE_H_ 5 #ifndef COMPRESSSOR_ARCHIVE_H_
6 #define COMPRESSSOR_ARCHIVE_H_ 6 #define COMPRESSSOR_ARCHIVE_H_
7 7
8 #include "compressor_io_javascript_stream.h" 8 #include "compressor_io_javascript_stream.h"
9 9
10 // Defines a wrapper for packing operations executed on an archive. API is not 10 // Defines a wrapper for packing operations executed on an archive. API is not
11 // meant to be thread safe and its methods shouldn't be called in parallel. 11 // meant to be thread safe and its methods shouldn't be called in parallel.
12 class CompressorArchive { 12 class CompressorArchive {
13 public: 13 public:
14 explicit CompressorArchive(CompressorStream* compressor_stream) 14 explicit CompressorArchive(CompressorStream* compressor_stream)
15 : compressor_stream_(compressor_stream) {} 15 : compressor_stream_(compressor_stream) {}
16 16
17 virtual ~CompressorArchive() {} 17 virtual ~CompressorArchive() {}
18 18
19 // Creates an archive object. This method does not call CustomArchiveWrite, so 19 // Creates an archive object. This method does not call CustomArchiveWrite, so
20 // this is synchronous. 20 // this is synchronous. Returns true if successful. In case of failure the
21 virtual void CreateArchive() = 0; 21 // error message can be obtained with CompressorArchive::error_message().
22 virtual bool CreateArchive() = 0;
22 23
23 // Releases all resources obtained by libarchive. 24 // Releases all resources obtained by libarchive.
mtomasz 2017/04/10 07:15:08 nit: libarchive -> minizip
takise 2017/04/11 06:00:51 Done.
24 // This method also writes metadata about the archive itself onto the end of 25 // This method also writes metadata about the archive itself onto the end of
25 // the archive file before releasing resources if hasError is false. Since 26 // the archive file before releasing resources if hasError is false. Since
26 // writing data onto the archive is asynchronous, this function must not be 27 // writing data onto the archive is asynchronous, this function must not be
27 // called in the main thread if hasError is false. 28 // called in the main thread if hasError is false. Returns true if successful.
28 virtual void CloseArchive(bool has_error) = 0; 29 // In case of failure the error message can be obtained with
30 // CompressorArchive::error_message().
31 virtual bool CloseArchive(bool has_error) = 0;
29 32
30 // Adds an entry to the archive. It writes the header of the entry onto the 33 // Adds an entry to the archive. It writes the header of the entry onto the
31 // archive first, and then if it is a file(not a directory), requests 34 // archive first, and then if it is a file(not a directory), requests
32 // JavaScript for file chunks, compresses and writes them onto the archive 35 // JavaScript for file chunks, compresses and writes them onto the archive
33 // until all chunks of the entry are written onto the archive. This method 36 // until all chunks of the entry are written onto the archive. This method
34 // calls IO operations, so this function must not be called in the main thread . 37 // calls IO operations, so this function must not be called in the main thread .
35 virtual void AddToArchive(const std::string& filename, 38 // Returns true if successful. In case of failure the error message can be
39 // obtained with CompressorArchive::error_message().
40 virtual bool AddToArchive(const std::string& filename,
36 int64_t file_size, 41 int64_t file_size,
37 time_t modification_time, 42 int64_t modification_time,
38 bool is_directory) = 0; 43 bool is_directory) = 0;
39 44
40 // A getter function for archive_.
41 struct archive* archive() const { return archive_; }
42
43 // A getter function for compressor_stream_. 45 // A getter function for compressor_stream_.
44 CompressorStream* compressor_stream() const { return compressor_stream_; } 46 CompressorStream* compressor_stream() const { return compressor_stream_; }
45 47
48 std::string error_message() const { return error_message_; }
49
50 void set_error_message(const std::string& error_message) {
51 error_message_ = error_message;
52 }
53
46 private: 54 private:
47 // The libarchive correspondent archive object.
48 struct archive* archive_;
49
50 // An instance that takes care of all IO operations. 55 // An instance that takes care of all IO operations.
51 CompressorStream* compressor_stream_; 56 CompressorStream* compressor_stream_;
57
58 // An error message set in case of any errors.
59 std::string error_message_;
52 }; 60 };
53 61
54 #endif // COMPRESSSOR_ARCHIVE_H_ 62 #endif // COMPRESSSOR_ARCHIVE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698