| OLD | NEW |
| 1 // Copyright 2014 The Chromium OS Authors. All rights reserved. | 1 // Copyright 2014 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 VOLUME_READER_H_ | 5 #ifndef VOLUME_READER_H_ |
| 6 #define VOLUME_READER_H_ | 6 #define VOLUME_READER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 // Defines a reader for archive volumes. This class is used by libarchive | 10 // Defines a reader for archive volumes. This class is used by minizip |
| 11 // for custom reads: https://github.com/libarchive/libarchive/wiki/Examples | 11 // for custom reads. |
| 12 class VolumeReader { | 12 class VolumeReader { |
| 13 public: | 13 public: |
| 14 virtual ~VolumeReader() {} | 14 virtual ~VolumeReader() {} |
| 15 | 15 |
| 16 // Tries to read bytes_to_read from the archive. The result will be stored at | 16 // Tries to read bytes_to_read from the archive. The result will be stored at |
| 17 // *destination_buffer, which is the address of a buffer handled by | 17 // *destination_buffer, which is the address of a buffer handled by |
| 18 // VolumeReaderJavaScriptStream. *destination_buffer must be available until | 18 // VolumeReaderJavaScriptStream. *destination_buffer must be available until |
| 19 // the next VolumeReader:Read call or until VolumeReader is destructed. | 19 // the next VolumeReader:Read call or until VolumeReader is destructed. |
| 20 // | 20 // |
| 21 // The operation must be synchronous (libarchive requirement), so it | 21 // The operation must be synchronous (minizip requirement), so it |
| 22 // should NOT be done on the main thread. bytes_to_read should be > 0. | 22 // should NOT be done on the main thread. bytes_to_read should be > 0. |
| 23 // | 23 // |
| 24 // Returns the actual number of read bytes or -1 in case of failure. | 24 // Returns the actual number of read bytes or -1 in case of failure. |
| 25 virtual int64_t Read(int64_t bytes_to_read, | 25 virtual int64_t Read(int64_t bytes_to_read, |
| 26 const void** destination_buffer) = 0; | 26 const void** destination_buffer) = 0; |
| 27 | 27 |
| 28 // Tries to seek to offset from whence. Returns the resulting offset location | 28 // Tries to seek to offset from whence. Returns the resulting offset location |
| 29 // or -1 in case of errors. Similar to | 29 // or -1 in case of errors. Similar to |
| 30 // http://www.cplusplus.com/reference/cstdio/fseek/ | 30 // http://www.cplusplus.com/reference/cstdio/fseek/ |
| 31 virtual int64_t Seek(int64_t offset, int whence) = 0; | 31 virtual int64_t Seek(int64_t offset, int whence) = 0; |
| 32 | 32 |
| 33 // Fetches a passphrase for reading. If the passphrase is not available it | 33 // Fetches a passphrase for reading. If the passphrase is not available it |
| 34 // returns nullptr. | 34 // returns nullptr. |
| 35 virtual const char* Passphrase() = 0; | 35 virtual const char* Passphrase() = 0; |
| 36 | 36 |
| 37 virtual int64_t offset() = 0; | 37 virtual int64_t offset() = 0; |
| 38 | 38 |
| 39 virtual int64_t archive_size() = 0; | 39 virtual int64_t archive_size() = 0; |
| 40 }; | 40 }; |
| 41 | 41 |
| 42 #endif // VOLUME_READER_H_ | 42 #endif // VOLUME_READER_H_ |
| OLD | NEW |