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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 // In the case of an asychronous write, the memory pointed to by |buf| must | 102 // In the case of an asychronous write, the memory pointed to by |buf| must |
103 // remain valid until the callback is notified. However, it is valid to | 103 // remain valid until the callback is notified. However, it is valid to |
104 // destroy or close the file stream while there is an asynchronous write in | 104 // destroy or close the file stream while there is an asynchronous write in |
105 // progress. That will cancel the write and allow the buffer to be freed. | 105 // progress. That will cancel the write and allow the buffer to be freed. |
106 // | 106 // |
107 // This method should not be called if the stream was opened READ_ONLY. | 107 // This method should not be called if the stream was opened READ_ONLY. |
108 // | 108 // |
109 // You can pass NULL as the callback for synchronous I/O. | 109 // You can pass NULL as the callback for synchronous I/O. |
110 int Write(const char* buf, int buf_len, CompletionCallback* callback); | 110 int Write(const char* buf, int buf_len, CompletionCallback* callback); |
111 | 111 |
| 112 // Truncates the file to be |bytes| length. This is only valid for writable |
| 113 // files. After truncation the file stream is positioned at |bytes|. The new |
| 114 // position is retured, or a value < 0 on error. |
| 115 int64 Truncate(int64 bytes); |
| 116 |
112 private: | 117 private: |
113 class AsyncContext; | 118 class AsyncContext; |
114 friend class AsyncContext; | 119 friend class AsyncContext; |
115 | 120 |
116 // This member is used to support asynchronous reads. It is non-null when | 121 // This member is used to support asynchronous reads. It is non-null when |
117 // the FileStream was opened with PLATFORM_FILE_ASYNC. | 122 // the FileStream was opened with PLATFORM_FILE_ASYNC. |
118 scoped_ptr<AsyncContext> async_context_; | 123 scoped_ptr<AsyncContext> async_context_; |
119 | 124 |
120 base::PlatformFile file_; | 125 base::PlatformFile file_; |
121 int open_flags_; | 126 int open_flags_; |
122 | 127 |
123 DISALLOW_COPY_AND_ASSIGN(FileStream); | 128 DISALLOW_COPY_AND_ASSIGN(FileStream); |
124 }; | 129 }; |
125 | 130 |
126 } // namespace net | 131 } // namespace net |
127 | 132 |
128 #endif // NET_BASE_FILE_STREAM_H_ | 133 #endif // NET_BASE_FILE_STREAM_H_ |
OLD | NEW |