OLD | NEW |
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. Use of this | 1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. Use of this |
2 // source code is governed by a BSD-style license that can be found in the | 2 // source code is governed by a BSD-style license that can be found in the |
3 // LICENSE file. | 3 // 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 25 matching lines...) Expand all Loading... |
36 // opened. | 36 // opened. |
37 FileStream(base::PlatformFile file, int flags); | 37 FileStream(base::PlatformFile file, int flags); |
38 | 38 |
39 ~FileStream(); | 39 ~FileStream(); |
40 | 40 |
41 // Call this method to close the FileStream. It is OK to call Close | 41 // Call this method to close the FileStream. It is OK to call Close |
42 // multiple times. Redundant calls are ignored. | 42 // multiple times. Redundant calls are ignored. |
43 // Note that if there are any pending async operations, they'll be aborted. | 43 // Note that if there are any pending async operations, they'll be aborted. |
44 void Close(); | 44 void Close(); |
45 | 45 |
| 46 // Release performs the same actions as Close, but doesn't actually close the |
| 47 // underlying PlatformFile. |
| 48 void Release(); |
| 49 |
46 // Call this method to open the FileStream. The remaining methods | 50 // Call this method to open the FileStream. The remaining methods |
47 // cannot be used unless this method returns OK. If the file cannot be | 51 // cannot be used unless this method returns OK. If the file cannot be |
48 // opened then an error code is returned. | 52 // opened then an error code is returned. |
49 // open_flags is a bitfield of base::PlatformFileFlags | 53 // open_flags is a bitfield of base::PlatformFileFlags |
50 int Open(const FilePath& path, int open_flags); | 54 int Open(const FilePath& path, int open_flags); |
51 | 55 |
52 // Returns true if Open succeeded and Close has not been called. | 56 // Calling this method is functionally the same as constructing the object |
| 57 // with the non-default constructor. This method can only be used if the |
| 58 // FileSteam isn't currently open (i.e. was constructed with the default |
| 59 // constructor). |
| 60 int Open(base::PlatformFile file, int open_flags); |
| 61 |
| 62 // Returns true if Open succeeded and neither Close nor Release have been |
| 63 // called. |
53 bool IsOpen() const; | 64 bool IsOpen() const; |
54 | 65 |
55 // Adjust the position from where data is read. Upon success, the stream | 66 // Adjust the position from where data is read. Upon success, the stream |
56 // position relative to the start of the file is returned. Otherwise, an | 67 // position relative to the start of the file is returned. Otherwise, an |
57 // error code is returned. It is not valid to call Seek while a Read call | 68 // error code is returned. It is not valid to call Seek while a Read call |
58 // has a pending completion. | 69 // has a pending completion. |
59 int64 Seek(Whence whence, int64 offset); | 70 int64 Seek(Whence whence, int64 offset); |
60 | 71 |
61 // Returns the number of bytes available to read from the current stream | 72 // Returns the number of bytes available to read from the current stream |
62 // position until the end of the file. Otherwise, an error code is returned. | 73 // position until the end of the file. Otherwise, an error code is returned. |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 | 139 |
129 base::PlatformFile file_; | 140 base::PlatformFile file_; |
130 int open_flags_; | 141 int open_flags_; |
131 | 142 |
132 DISALLOW_COPY_AND_ASSIGN(FileStream); | 143 DISALLOW_COPY_AND_ASSIGN(FileStream); |
133 }; | 144 }; |
134 | 145 |
135 } // namespace net | 146 } // namespace net |
136 | 147 |
137 #endif // NET_BASE_FILE_STREAM_H_ | 148 #endif // NET_BASE_FILE_STREAM_H_ |
OLD | NEW |