diff options
author | halcanary <halcanary@google.com> | 2015-08-18 13:30:25 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-08-18 13:30:25 -0700 |
commit | 48305e835351291ef72a7084c6c1af7b185d89c0 (patch) | |
tree | 56cf2a20e842163148bb212f9ab606deede363d4 /src/core/SkStream.cpp | |
parent | a44919ea27acd9808a7581362018484355c0f026 (diff) |
SkPDF/Deflate: clean up old SkFlate code
Factor out some of https://crrev.com/1227913008
BUG=skia:3030
Review URL: https://codereview.chromium.org/1298243002
Diffstat (limited to 'src/core/SkStream.cpp')
-rw-r--r-- | src/core/SkStream.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/core/SkStream.cpp b/src/core/SkStream.cpp index ac73adbce5..f32f68a10a 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; + } + } +} |