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

Unified Diff: src/utils/SkFrontBufferedStream.cpp

Issue 1044953002: Add a method to read a stream without advancing it. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Use kEnums. Created 5 years, 9 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: src/utils/SkFrontBufferedStream.cpp
diff --git a/src/utils/SkFrontBufferedStream.cpp b/src/utils/SkFrontBufferedStream.cpp
index f23b1f99c4c6da1c98f8b947647ce977421546e8..4223dd4ad68087d27cbb4d6ea32c33a8203eb875 100644
--- a/src/utils/SkFrontBufferedStream.cpp
+++ b/src/utils/SkFrontBufferedStream.cpp
@@ -16,6 +16,8 @@ public:
size_t read(void* buffer, size_t size) override;
+ size_t peek(void* buffer, size_t size) override;
+
bool isAtEnd() const override;
bool rewind() override;
@@ -155,6 +157,20 @@ size_t FrontBufferedStream::readDirectlyFromStream(char* dst, size_t size) {
return bytesReadDirectly;
}
+size_t FrontBufferedStream::peek(void* dst, size_t size) {
+ // Keep track of the offset so we can return to it.
+ const size_t start = fOffset;
+ if (start >= fBufferSize) {
+ // This stream is not able to buffer any more.
+ return kUnsupported_PeekResult;
+ }
+ // Do not read more than we can buffer.
+ const size_t bytesToRead = SkTMin(size, fBufferSize - start);
+ const size_t bytesRead = this->read(dst, bytesToRead);
+ fOffset = start;
+ return bytesRead;
+}
+
size_t FrontBufferedStream::read(void* voidDst, size_t size) {
// Cast voidDst to a char* for easy addition.
char* dst = reinterpret_cast<char*>(voidDst);
« no previous file with comments | « include/core/SkStream.h ('k') | tests/StreamTest.cpp » ('j') | tests/StreamTest.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698