Index: webrtc/base/file.h |
diff --git a/webrtc/base/file.h b/webrtc/base/file.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..5bb9f16e7454f03441a4c3da35d8b32e034d127c |
--- /dev/null |
+++ b/webrtc/base/file.h |
@@ -0,0 +1,61 @@ |
+/* |
+ * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
+ * |
+ * Use of this source code is governed by a BSD-style license |
+ * that can be found in the LICENSE file in the root of the source |
+ * tree. An additional intellectual property rights grant can be found |
+ * in the file PATENTS. All contributing project authors may |
+ * be found in the AUTHORS file in the root of the source tree. |
+ */ |
+ |
+#ifndef WEBRTC_BASE_FILE_H_ |
+#define WEBRTC_BASE_FILE_H_ |
+ |
+#include <stdint.h> |
+ |
+#include "webrtc/base/platform_file.h" |
+#include "webrtc/base/constructormagic.h" |
+ |
+namespace rtc { |
+ |
+// This class wraps the platform specific APIs for simple file interactions. |
+// |
+// The regular read and write methods (Write|Read)(At)? are best effort, i.e. |
+// if an underlying call does not manage to read/write all the data more calls |
+// will be performed, until an error is detected or all data is read/written. |
+// The NoBestEffort variants do not do this. |
sprang_webrtc
2016/08/15 09:43:07
I'm thinking we should switch this naming around,
palmkvist
2016/08/16 08:55:35
I agree that WriteAll should be the default, but I
sprang
2016/08/16 09:27:44
Agreed, let's only add a best-effort method if we
|
+class File { |
+ public: |
+ // Wraps the given PlatformFile. This class is then responsible for closing |
+ // the file, which will be done in the destructor if Close is never called. |
+ explicit File(PlatformFile); |
+ ~File(); |
+ |
+ size_t Write(const uint8_t* data, size_t length); |
+ size_t Read(uint8_t* buffer, size_t length); |
+ |
+ size_t WriteAt(const uint8_t* data, size_t length, size_t offset); |
+ size_t ReadAt(uint8_t* buffer, size_t length, size_t offset); |
+ |
+ size_t WriteNoBestEffort(const uint8_t* data, size_t length); |
+ size_t ReadNoBestEffort(uint8_t* buffer, size_t length); |
+ |
+ size_t WriteAtNoBestEffort(const uint8_t* data, size_t length, size_t offset); |
+ size_t ReadAtNoBestEffort(uint8_t* buffer, size_t length, size_t offset); |
+ |
+ // Attempt to position the file at the given offset from the start. |
+ // Returns true if successful, false otherwise. |
+ bool Seek(size_t offset); |
+ |
+ // Attempt to close the file. Returns true if successful, false otherwise, |
+ // most notably when the file is already closed. |
+ bool Close(); |
+ |
+ private: |
+ rtc::PlatformFile file_; |
+ RTC_DISALLOW_COPY_AND_ASSIGN(File); |
+}; |
+ |
+} // namespace rtc |
+ |
+#endif // WEBRTC_BASE_FILE_H_ |