| OLD | NEW |
| 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_STREAM_H_ | 5 #ifndef COMPRESSOR_STREAM_H_ |
| 6 #define COMPRESSOR_STREAM_H_ | 6 #define COMPRESSOR_STREAM_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 // A IO class that reads and writes data from and to files through JavaScript. | 10 // A IO class that reads and writes data from and to files through JavaScript. |
| 11 // Currently, Read() and Write() methods are not called at the same time. | 11 // Currently, Read() and Write() methods are not called at the same time. |
| 12 // To improve the performance, these should be called in parallel by preparing | 12 // To improve the performance, these should be called in parallel by preparing |
| 13 // two buffers and calling them with these buffers alternatively. | 13 // two buffers and calling them with these buffers alternatively. |
| 14 class CompressorStream { | 14 class CompressorStream { |
| 15 public: | 15 public: |
| 16 virtual ~CompressorStream() {} | 16 virtual ~CompressorStream() {} |
| 17 | 17 |
| 18 // Flush the data in buffer_. This method is called when the buffer gets full |
| 19 // or needs to have the different range of data from the current data in it. |
| 20 // This method must not be called in the main thread. |
| 21 virtual int64_t Flush() = 0; |
| 22 |
| 18 // Writes the given buffer onto the archive. After sending a write chunk | 23 // Writes the given buffer onto the archive. After sending a write chunk |
| 19 // request to JavaScript, it waits until WriteChunkDone() is called in the | 24 // request to JavaScript, it waits until WriteChunkDone() is called in the |
| 20 // main thread. Thus, This method must not be called in the main thread. | 25 // main thread. Thus, This method must not be called in the main thread. |
| 21 virtual int64_t Write(int64_t bytes_to_write, | 26 virtual int64_t Write(int64_t zip_offset, |
| 22 const pp::VarArrayBuffer& buffer) = 0; | 27 int64_t zip_length, |
| 28 const char* zip_buffer) = 0; |
| 23 | 29 |
| 24 // Called when write chunk done response arrives from JavaScript. Sends a | 30 // Called when write chunk done response arrives from JavaScript. Sends a |
| 25 // signal to invoke Write function in another thread again. | 31 // signal to invoke Write function in another thread again. |
| 26 virtual void WriteChunkDone(int64_t write_bytes) = 0; | 32 virtual int64_t WriteChunkDone(int64_t write_bytes) = 0; |
| 27 | 33 |
| 28 // Reads a file chunk from the entry that is currently being processed. After | 34 // Reads a file chunk from the entry that is currently being processed. After |
| 29 // sending a read file chunk request to JavaScript, it waits until | 35 // sending a read file chunk request to JavaScript, it waits until |
| 30 // ReadFileChunkDone() is called in the main thread. Thus, This method must | 36 // ReadFileChunkDone() is called in the main thread. Thus, This method must |
| 31 // not be called in the main thread. | 37 // not be called in the main thread. |
| 32 virtual int64_t Read(int64_t bytes_to_read, char* destination_buffer) = 0; | 38 virtual int64_t Read(int64_t bytes_to_read, char* destination_buffer) = 0; |
| 33 | 39 |
| 34 // Called when read file chunk done response arrives from JavaScript. Copies | 40 // Called when read file chunk done response arrives from JavaScript. Copies |
| 35 // the binary data in the given buffer to destination_buffer_ and Sends a | 41 // the binary data in the given buffer to destination_buffer_ and Sends a |
| 36 // signal to invoke Read function in another thread again. buffer must not be | 42 // signal to invoke Read function in another thread again. buffer must not be |
| 37 // const because buffer.Map() and buffer.Unmap() can not be called with const. | 43 // const because buffer.Map() and buffer.Unmap() can not be called with const. |
| 38 virtual void ReadFileChunkDone(int64_t read_bytes, | 44 virtual int64_t ReadFileChunkDone(int64_t read_bytes, |
| 39 pp::VarArrayBuffer* buffer) = 0; | 45 pp::VarArrayBuffer* buffer) = 0; |
| 40 }; | 46 }; |
| 41 | 47 |
| 42 #endif // COMPRESSOR_STREAM_H_ | 48 #endif // COMPRESSOR_STREAM_H_ |
| OLD | NEW |