| Index: src/core/SkStream.cpp
|
| diff --git a/src/core/SkStream.cpp b/src/core/SkStream.cpp
|
| index ac73adbce54e2045992dbe19903e80ae9207b61b..f32f68a10ab668f06323d690166eaf7b892398b5 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 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];
|
| + size_t count;
|
| + while (true) {
|
| + count = input->read(scratch, sizeof(scratch));
|
| + if (0 == count) {
|
| + return true;
|
| + }
|
| + if (!out->write(scratch, count)) {
|
| + return false;
|
| + }
|
| + }
|
| +}
|
|
|