| OLD | NEW | 
|---|
|  | (Empty) | 
| 1 /* |  | 
| 2  *  Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |  | 
| 3  * |  | 
| 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 |  | 
| 6  *  tree. An additional intellectual property rights grant can be found |  | 
| 7  *  in the file PATENTS.  All contributing project authors may |  | 
| 8  *  be found in the AUTHORS file in the root of the source tree. |  | 
| 9  */ |  | 
| 10 |  | 
| 11 #ifndef WEBRTC_BASE_FILE_H_ |  | 
| 12 #define WEBRTC_BASE_FILE_H_ |  | 
| 13 |  | 
| 14 #include <stdint.h> |  | 
| 15 |  | 
| 16 #include <string> |  | 
| 17 |  | 
| 18 #include "webrtc/base/platform_file.h" |  | 
| 19 #include "webrtc/base/constructormagic.h" |  | 
| 20 |  | 
| 21 namespace rtc { |  | 
| 22 |  | 
| 23 // This class wraps the platform specific APIs for simple file interactions. |  | 
| 24 // |  | 
| 25 // 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 // until an error is detected or all data is read/written. |  | 
| 28 class File { |  | 
| 29  public: |  | 
| 30   // 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   explicit File(PlatformFile); |  | 
| 33   ~File(); |  | 
| 34 |  | 
| 35   File(File&& other); |  | 
| 36   File& operator=(File&& other); |  | 
| 37 |  | 
| 38   static File Open(const std::string& path); |  | 
| 39 |  | 
| 40   size_t Write(const uint8_t* data, size_t length); |  | 
| 41   size_t Read(uint8_t* buffer, size_t length); |  | 
| 42 |  | 
| 43   // The current position in the file after a call to these methods is platform |  | 
| 44   // dependent (MSVC gives position offset+length, most other |  | 
| 45   // compilers/platforms do not alter the position), i.e. do not depend on it, |  | 
| 46   // do a Seek before any subsequent Read/Write. |  | 
| 47   size_t WriteAt(const uint8_t* data, size_t length, size_t offset); |  | 
| 48   size_t ReadAt(uint8_t* buffer, size_t length, size_t offset); |  | 
| 49 |  | 
| 50   // Attempt to position the file at the given offset from the start. |  | 
| 51   // Returns true if successful, false otherwise. |  | 
| 52   bool Seek(size_t offset); |  | 
| 53 |  | 
| 54   // Attempt to close the file. Returns true if successful, false otherwise, |  | 
| 55   // most notably when the file is already closed. |  | 
| 56   bool Close(); |  | 
| 57 |  | 
| 58   bool IsOpen(); |  | 
| 59 |  | 
| 60  private: |  | 
| 61   PlatformFile file_; |  | 
| 62   RTC_DISALLOW_COPY_AND_ASSIGN(File); |  | 
| 63 }; |  | 
| 64 |  | 
| 65 }  // namespace rtc |  | 
| 66 |  | 
| 67 #endif  // WEBRTC_BASE_FILE_H_ |  | 
| OLD | NEW | 
|---|