| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #ifndef WEBRTC_BASE_FILE_H_ | 11 #ifndef WEBRTC_BASE_FILE_H_ |
| 12 #define WEBRTC_BASE_FILE_H_ | 12 #define WEBRTC_BASE_FILE_H_ |
| 13 | 13 |
| 14 #include <stdint.h> | 14 #include <stdint.h> |
| 15 | 15 |
| 16 #include <string> | 16 #include <string> |
| 17 | 17 |
| 18 #include "webrtc/base/constructormagic.h" |
| 19 #include "webrtc/base/pathutils.h" |
| 18 #include "webrtc/base/platform_file.h" | 20 #include "webrtc/base/platform_file.h" |
| 19 #include "webrtc/base/constructormagic.h" | |
| 20 | 21 |
| 21 namespace rtc { | 22 namespace rtc { |
| 22 | 23 |
| 23 // This class wraps the platform specific APIs for simple file interactions. | 24 // This class wraps the platform specific APIs for simple file interactions. |
| 24 // | 25 // |
| 25 // The various read and write methods are best effort, i.e. if an underlying | 26 // The various read and write methods are best effort, i.e. if an underlying |
| 26 // call does not manage to read/write all the data more calls will be performed, | 27 // call does not manage to read/write all the data more calls will be performed, |
| 27 // until an error is detected or all data is read/written. | 28 // until an error is detected or all data is read/written. |
| 28 class File { | 29 class File { |
| 29 public: | 30 public: |
| 30 // Wraps the given PlatformFile. This class is then responsible for closing | 31 // Wraps the given PlatformFile. This class is then responsible for closing |
| 31 // the file, which will be done in the destructor if Close is never called. | 32 // the file, which will be done in the destructor if Close is never called. |
| 32 explicit File(PlatformFile); | 33 explicit File(PlatformFile); |
| 33 // The default constructor produces a closed file. | 34 // The default constructor produces a closed file. |
| 34 File(); | 35 File(); |
| 35 ~File(); | 36 ~File(); |
| 36 | 37 |
| 37 File(File&& other); | 38 File(File&& other); |
| 38 File& operator=(File&& other); | 39 File& operator=(File&& other); |
| 39 | 40 |
| 40 // Open and Create give files with both reading and writing enabled. | 41 // Open and Create give files with both reading and writing enabled. |
| 41 static File Open(const std::string& path); | 42 static File Open(const std::string& path); |
| 43 static File Open(Pathname&& path); |
| 44 static File Open(const Pathname& path); |
| 42 // If the file already exists it will be overwritten. | 45 // If the file already exists it will be overwritten. |
| 43 static File Create(const std::string& path); | 46 static File Create(const std::string& path); |
| 47 static File Create(Pathname&& path); |
| 48 static File Create(const Pathname& path); |
| 44 | 49 |
| 45 size_t Write(const uint8_t* data, size_t length); | 50 size_t Write(const uint8_t* data, size_t length); |
| 46 size_t Read(uint8_t* buffer, size_t length); | 51 size_t Read(uint8_t* buffer, size_t length); |
| 47 | 52 |
| 48 // The current position in the file after a call to these methods is platform | 53 // The current position in the file after a call to these methods is platform |
| 49 // dependent (MSVC gives position offset+length, most other | 54 // dependent (MSVC gives position offset+length, most other |
| 50 // compilers/platforms do not alter the position), i.e. do not depend on it, | 55 // compilers/platforms do not alter the position), i.e. do not depend on it, |
| 51 // do a Seek before any subsequent Read/Write. | 56 // do a Seek before any subsequent Read/Write. |
| 52 size_t WriteAt(const uint8_t* data, size_t length, size_t offset); | 57 size_t WriteAt(const uint8_t* data, size_t length, size_t offset); |
| 53 size_t ReadAt(uint8_t* buffer, size_t length, size_t offset); | 58 size_t ReadAt(uint8_t* buffer, size_t length, size_t offset); |
| 54 | 59 |
| 55 // Attempt to position the file at the given offset from the start. | 60 // Attempt to position the file at the given offset from the start. |
| 56 // Returns true if successful, false otherwise. | 61 // Returns true if successful, false otherwise. |
| 57 bool Seek(size_t offset); | 62 bool Seek(size_t offset); |
| 58 | 63 |
| 59 // Attempt to close the file. Returns true if successful, false otherwise, | 64 // Attempt to close the file. Returns true if successful, false otherwise, |
| 60 // most notably when the file is already closed. | 65 // most notably when the file is already closed. |
| 61 bool Close(); | 66 bool Close(); |
| 62 | 67 |
| 63 bool IsOpen(); | 68 bool IsOpen(); |
| 64 | 69 |
| 65 private: | 70 private: |
| 66 PlatformFile file_; | 71 PlatformFile file_; |
| 67 RTC_DISALLOW_COPY_AND_ASSIGN(File); | 72 RTC_DISALLOW_COPY_AND_ASSIGN(File); |
| 68 }; | 73 }; |
| 69 | 74 |
| 70 } // namespace rtc | 75 } // namespace rtc |
| 71 | 76 |
| 72 #endif // WEBRTC_BASE_FILE_H_ | 77 #endif // WEBRTC_BASE_FILE_H_ |
| OLD | NEW |