| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef COMPRESSSOR_ARCHIVE_H_ | |
| 6 #define COMPRESSSOR_ARCHIVE_H_ | |
| 7 | |
| 8 #include "compressor_io_javascript_stream.h" | |
| 9 | |
| 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. | |
| 12 class CompressorArchive { | |
| 13 public: | |
| 14 explicit CompressorArchive(CompressorStream* compressor_stream) | |
| 15 : compressor_stream_(compressor_stream) {} | |
| 16 | |
| 17 virtual ~CompressorArchive() {} | |
| 18 | |
| 19 // Creates an archive object. This method does not call CustomArchiveWrite, so | |
| 20 // this is synchronous. | |
| 21 virtual void CreateArchive() = 0; | |
| 22 | |
| 23 // Releases all resources obtained by libarchive. | |
| 24 // 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 // writing data onto the archive is asynchronous, this function must not be | |
| 27 // called in the main thread if hasError is false. | |
| 28 virtual void CloseArchive(bool has_error) = 0; | |
| 29 | |
| 30 // 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 | |
| 32 // 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 | |
| 34 // calls IO operations, so this function must not be called in the main thread
. | |
| 35 virtual void AddToArchive(const std::string& filename, | |
| 36 int64_t file_size, | |
| 37 time_t modification_time, | |
| 38 bool is_directory) = 0; | |
| 39 | |
| 40 // A getter function for archive_. | |
| 41 struct archive* archive() const { return archive_; } | |
| 42 | |
| 43 // A getter function for compressor_stream_. | |
| 44 CompressorStream* compressor_stream() const { return compressor_stream_; } | |
| 45 | |
| 46 private: | |
| 47 // The libarchive correspondent archive object. | |
| 48 struct archive* archive_; | |
| 49 | |
| 50 // An instance that takes care of all IO operations. | |
| 51 CompressorStream* compressor_stream_; | |
| 52 }; | |
| 53 | |
| 54 #endif // COMPRESSSOR_ARCHIVE_H_ | |
| OLD | NEW |