| 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_ |
| 11 #define NET_BASE_FILE_STREAM_H_ | 11 #define NET_BASE_FILE_STREAM_H_ |
| 12 | 12 |
| 13 #include "base/file_path.h" |
| 13 #include "base/platform_file.h" | 14 #include "base/platform_file.h" |
| 14 #include "net/base/completion_callback.h" | 15 #include "net/base/completion_callback.h" |
| 15 | 16 |
| 16 namespace net { | 17 namespace net { |
| 17 | 18 |
| 18 // TODO(darin): Move this to a more generic location. | 19 // TODO(darin): Move this to a more generic location. |
| 19 // This explicit mapping matches both FILE_ on Windows and SEEK_ on Linux. | 20 // This explicit mapping matches both FILE_ on Windows and SEEK_ on Linux. |
| 20 enum Whence { | 21 enum Whence { |
| 21 FROM_BEGIN = 0, | 22 FROM_BEGIN = 0, |
| 22 FROM_CURRENT = 1, | 23 FROM_CURRENT = 1, |
| 23 FROM_END = 2 | 24 FROM_END = 2 |
| 24 }; | 25 }; |
| 25 | 26 |
| 26 class FileStream { | 27 class FileStream { |
| 27 public: | 28 public: |
| 28 FileStream(); | 29 FileStream(); |
| 29 ~FileStream(); | 30 ~FileStream(); |
| 30 | 31 |
| 31 // Call this method to close the FileStream. It is OK to call Close | 32 // Call this method to close the FileStream. It is OK to call Close |
| 32 // multiple times. Redundant calls are ignored. | 33 // multiple times. Redundant calls are ignored. |
| 33 // Note that if there are any pending async operations, they'll be aborted. | 34 // Note that if there are any pending async operations, they'll be aborted. |
| 34 void Close(); | 35 void Close(); |
| 35 | 36 |
| 36 // Call this method to open the FileStream. The remaining methods | 37 // Call this method to open the FileStream. The remaining methods |
| 37 // cannot be used unless this method returns OK. If the file cannot be | 38 // cannot be used unless this method returns OK. If the file cannot be |
| 38 // opened then an error code is returned. | 39 // opened then an error code is returned. |
| 39 // open_flags is a bitfield of base::PlatformFileFlags | 40 // open_flags is a bitfield of base::PlatformFileFlags |
| 40 int Open(const std::wstring& path, int open_flags); | 41 int Open(const FilePath& path, int open_flags); |
| 41 | 42 |
| 42 // Returns true if Open succeeded and Close has not been called. | 43 // Returns true if Open succeeded and Close has not been called. |
| 43 bool IsOpen() const; | 44 bool IsOpen() const; |
| 44 | 45 |
| 45 // Adjust the position from where data is read. Upon success, the stream | 46 // Adjust the position from where data is read. Upon success, the stream |
| 46 // position relative to the start of the file is returned. Otherwise, an | 47 // position relative to the start of the file is returned. Otherwise, an |
| 47 // error code is returned. It is not valid to call Seek while a Read call | 48 // error code is returned. It is not valid to call Seek while a Read call |
| 48 // has a pending completion. | 49 // has a pending completion. |
| 49 int64 Seek(Whence whence, int64 offset); | 50 int64 Seek(Whence whence, int64 offset); |
| 50 | 51 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 | 105 |
| 105 base::PlatformFile file_; | 106 base::PlatformFile file_; |
| 106 int open_flags_; | 107 int open_flags_; |
| 107 | 108 |
| 108 DISALLOW_COPY_AND_ASSIGN(FileStream); | 109 DISALLOW_COPY_AND_ASSIGN(FileStream); |
| 109 }; | 110 }; |
| 110 | 111 |
| 111 } // namespace net | 112 } // namespace net |
| 112 | 113 |
| 113 #endif // NET_BASE_FILE_STREAM_H_ | 114 #endif // NET_BASE_FILE_STREAM_H_ |
| OLD | NEW |