Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(404)

Unified Diff: webrtc/base/file.cc

Issue 2214763002: Initial version of new file wrapper (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Test random access better Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/base/file.cc
diff --git a/webrtc/base/file.cc b/webrtc/base/file.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8a9d1246c85f535f9581c34b010fcd8019b8c045
--- /dev/null
+++ b/webrtc/base/file.cc
@@ -0,0 +1,68 @@
+/*
+ * 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.
+ */
+
+#include "webrtc/base/file.h"
+
+namespace rtc {
+
+File::File(rtc::PlatformFile file) : file_(file) {}
+
+File::~File() {
+ Close();
+}
+
+size_t File::Write(const uint8_t* data, size_t length) {
+ size_t total_written = 0;
+ do {
+ size_t written =
+ WriteNoBestEffort(data + total_written, length - total_written);
+ if (written == 0)
+ break;
+ total_written += written;
+ } while (total_written < length);
+ return total_written;
+}
+
+size_t File::Read(uint8_t* buffer, size_t length) {
+ size_t total_read = 0;
+ do {
+ size_t read = ReadNoBestEffort(buffer + total_read, length - total_read);
+ if (read == 0)
+ break;
+ total_read += read;
+ } while (total_read < length);
+ return total_read;
+}
+
+size_t File::WriteAt(const uint8_t* data, size_t length, size_t offset) {
+ size_t total_written = 0;
+ do {
+ size_t written = WriteAtNoBestEffort(
+ data + total_written, length - total_written, offset + total_written);
+ if (written == 0)
+ break;
+ total_written += written;
+ } while (total_written < length);
+ return total_written;
+}
+
+size_t File::ReadAt(uint8_t* buffer, size_t length, size_t offset) {
+ size_t total_read = 0;
+ do {
+ size_t read = ReadAtNoBestEffort(buffer + total_read, length - total_read,
+ offset + total_read);
+ if (read == 0)
+ break;
+ total_read += read;
+ } while (total_read < length);
+ return total_read;
+}
+
+} // namespace rtc

Powered by Google App Engine
This is Rietveld 408576698