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