Index: src/utils/SkDataUtils.cpp |
diff --git a/src/utils/SkDataUtils.cpp b/src/utils/SkDataUtils.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c5544f71ba3e5a8dc9d74ae0a8b2670564455d32 |
--- /dev/null |
+++ b/src/utils/SkDataUtils.cpp |
@@ -0,0 +1,28 @@ |
+/* |
+ * Copyright 2014 Google Inc. |
+ * |
+ * Use of this source code is governed by a BSD-style license that can be |
+ * found in the LICENSE file. |
+ */ |
+ |
+#include "SkData.h" |
+#include "SkDataUtils.h" |
+#include "SkStream.h" |
+ |
+/*static*/ SkData* SkDataUtils::ReadIntoSkData(SkStream &stream, size_t maxBytes) { |
+ if (0 == maxBytes) { |
+ return SkData::NewEmpty(); |
+ } |
+ char* bufStart = reinterpret_cast<char *>(sk_malloc_throw(maxBytes)); |
+ char* bufPtr = bufStart; |
+ size_t bytesRemaining = maxBytes; |
+ while (bytesRemaining > 0) { |
+ size_t bytesReadThisTime = stream.read(bufPtr, bytesRemaining); |
+ if (0 == bytesReadThisTime) { |
+ break; |
+ } |
+ bytesRemaining -= bytesReadThisTime; |
+ bufPtr += bytesReadThisTime; |
+ } |
+ return SkData::NewFromMalloc(bufStart, maxBytes - bytesRemaining); |
+} |