| 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   virtual int64_t Flush() = 0; | 
|  | 19 | 
| 18   // Writes the given buffer onto the archive. After sending a write chunk | 20   // Writes the given buffer onto the archive. After sending a write chunk | 
| 19   // request to JavaScript, it waits until WriteChunkDone() is called in the | 21   // 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. | 22   // main thread. Thus, This method must not be called in the main thread. | 
| 21   virtual int64_t Write(int64_t bytes_to_write, | 23   virtual int64_t Write(int64_t zip_offset, | 
| 22                         const pp::VarArrayBuffer& buffer) = 0; | 24                         int64_t zip_length, | 
|  | 25                         const void* zip_buffer) = 0; | 
| 23 | 26 | 
| 24   // Called when write chunk done response arrives from JavaScript. Sends a | 27   // Called when write chunk done response arrives from JavaScript. Sends a | 
| 25   // signal to invoke Write function in another thread again. | 28   // signal to invoke Write function in another thread again. | 
| 26   virtual void WriteChunkDone(int64_t write_bytes) = 0; | 29   virtual int64_t WriteChunkDone(int64_t write_bytes) = 0; | 
| 27 | 30 | 
| 28   // Reads a file chunk from the entry that is currently being processed. After | 31   // 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 | 32   // sending a read file chunk request to JavaScript, it waits until | 
| 30   // ReadFileChunkDone() is called in the main thread. Thus, This method must | 33   // ReadFileChunkDone() is called in the main thread. Thus, This method must | 
| 31   // not be called in the main thread. | 34   // not be called in the main thread. | 
| 32   virtual int64_t Read(int64_t bytes_to_read, char* destination_buffer) = 0; | 35   virtual int64_t Read(int64_t bytes_to_read, char* destination_buffer) = 0; | 
| 33 | 36 | 
| 34   // Called when read file chunk done response arrives from JavaScript. Copies | 37   // 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 | 38   // 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 | 39   // 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. | 40   // const because buffer.Map() and buffer.Unmap() can not be called with const. | 
| 38   virtual void ReadFileChunkDone(int64_t read_bytes, | 41   virtual int64_t ReadFileChunkDone(int64_t read_bytes, | 
| 39                                  pp::VarArrayBuffer* buffer) = 0; | 42                                     pp::VarArrayBuffer* buffer) = 0; | 
| 40 }; | 43 }; | 
| 41 | 44 | 
| 42 #endif  // COMPRESSOR_STREAM_H_ | 45 #endif  // COMPRESSOR_STREAM_H_ | 
| OLD | NEW | 
|---|