| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium 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 // This file defines FileStream, a basic interface for reading and writing files | 5 // This file defines FileStream, a basic interface for reading and writing files |
| 6 // synchronously or asynchronously with support for seeking to an offset. | 6 // synchronously or asynchronously with support for seeking to an offset. |
| 7 // Note that even when used asynchronously, only one operation is supported at | 7 // Note that even when used asynchronously, only one operation is supported at |
| 8 // a time. | 8 // a time. |
| 9 | 9 |
| 10 #ifndef NET_BASE_FILE_STREAM_H_ | 10 #ifndef NET_BASE_FILE_STREAM_H_ |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 // the file cannot be opened then an error code is returned. open_flags is | 87 // the file cannot be opened then an error code is returned. open_flags is |
| 88 // a bitfield of base::PlatformFileFlags | 88 // a bitfield of base::PlatformFileFlags |
| 89 // | 89 // |
| 90 // If the file stream is not closed manually, the underlying file will be | 90 // If the file stream is not closed manually, the underlying file will be |
| 91 // automatically closed when FileStream is destructed. | 91 // automatically closed when FileStream is destructed. |
| 92 virtual int OpenSync(const FilePath& path, int open_flags); | 92 virtual int OpenSync(const FilePath& path, int open_flags); |
| 93 | 93 |
| 94 // Returns true if Open succeeded and Close has not been called. | 94 // Returns true if Open succeeded and Close has not been called. |
| 95 virtual bool IsOpen() const; | 95 virtual bool IsOpen() const; |
| 96 | 96 |
| 97 // Adjust the position from where data is read. Upon success, the stream | 97 // Adjust the position from where data is read asynchronously. |
| 98 // position relative to the start of the file is returned. Otherwise, an | 98 // Upon success, ERR_IO_PENDING is returned and |callback| will be run |
| 99 // error code is returned. It is not valid to call Seek while a Read call | 99 // on the thread where Seek() was called with the the stream position |
| 100 // has a pending completion. | 100 // relative to the start of the file. Otherwise, an error code is returned. |
| 101 virtual int64 Seek(Whence whence, int64 offset); | 101 // It is invalid to request any asynchronous operations while there is an |
| 102 // in-flight asynchronous operation. |
| 103 virtual int Seek(Whence whence, int64 offset, |
| 104 const Int64CompletionCallback& callback); |
| 105 |
| 106 // Adjust the position from where data is read synchronously. |
| 107 // Upon success, the stream position relative to the start of the file is |
| 108 // returned. Otherwise, an error code is returned. It is not valid to |
| 109 // call SeekSync while a Read call has a pending completion. |
| 110 virtual int64 SeekSync(Whence whence, int64 offset); |
| 102 | 111 |
| 103 // Returns the number of bytes available to read from the current stream | 112 // Returns the number of bytes available to read from the current stream |
| 104 // position until the end of the file. Otherwise, an error code is returned. | 113 // position until the end of the file. Otherwise, an error code is returned. |
| 105 virtual int64 Available(); | 114 virtual int64 Available(); |
| 106 | 115 |
| 107 // Call this method to read data from the current stream position | 116 // Call this method to read data from the current stream position |
| 108 // asynchronously. Up to buf_len bytes will be copied into buf. (In | 117 // asynchronously. Up to buf_len bytes will be copied into buf. (In |
| 109 // other words, partial reads are allowed.) Returns the number of bytes | 118 // other words, partial reads are allowed.) Returns the number of bytes |
| 110 // copied, 0 if at end-of-file, or an error code if the operation could | 119 // copied, 0 if at end-of-file, or an error code if the operation could |
| 111 // not be performed. | 120 // not be performed. |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 #elif defined(OS_POSIX) | 222 #elif defined(OS_POSIX) |
| 214 FileStreamPosix impl_; | 223 FileStreamPosix impl_; |
| 215 #endif | 224 #endif |
| 216 | 225 |
| 217 DISALLOW_COPY_AND_ASSIGN(FileStream); | 226 DISALLOW_COPY_AND_ASSIGN(FileStream); |
| 218 }; | 227 }; |
| 219 | 228 |
| 220 } // namespace net | 229 } // namespace net |
| 221 | 230 |
| 222 #endif // NET_BASE_FILE_STREAM_H_ | 231 #endif // NET_BASE_FILE_STREAM_H_ |
| OLD | NEW |