Index: src/core/SkStream.cpp |
diff --git a/src/core/SkStream.cpp b/src/core/SkStream.cpp |
index ac73adbce54e2045992dbe19903e80ae9207b61b..d6710fb8bf468e31df8d8ad3d561604121d28a5d 100644 |
--- a/src/core/SkStream.cpp |
+++ b/src/core/SkStream.cpp |
@@ -950,3 +950,25 @@ SkStreamRewindable* SkStreamRewindableFromSkStream(SkStream* stream) { |
return tempStream.detachAsStream(); // returns a SkBlockMemoryStream, |
// cheaper than copying to SkData |
} |
+ |
+bool SkStreamCopy(SkWStream* out, SkStream* input) { |
+ const char* base = static_cast<const char*>(input->getMemoryBase()); |
+ if (base && input->hasPosition() && input->hasLength()) { |
+ // Shortcut that avoids the do-while loop. |
+ size_t position = input->getPosition(); |
+ size_t length = input->getLength(); |
+ SkASSERT(length >= position); |
+ return out->write(&base[position], length - position); |
+ } |
+ char scratch[4096]; |
mtklein_C
2015/08/18 19:33:09
Let's make sure this path is tested too.
hal.canary
2015/08/18 20:06:23
Done.
|
+ size_t count; |
+ while (true) { |
+ count = input->read(scratch, sizeof(scratch)); |
+ if (0 == count) { |
+ return true; |
+ } |
+ if (!out->write(scratch, count)) { |
+ return false; |
+ } |
+ } |
+} |