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

Unified Diff: src/core/SkStream.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: Stop declaring parameters I do not use. 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
« no previous file with comments | « include/core/SkStream.h ('k') | src/utils/SkFrontBufferedStream.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkStream.cpp
diff --git a/src/core/SkStream.cpp b/src/core/SkStream.cpp
index 426f5569e887fe83e4aee8b38c412587abfa1fe2..ad67a0ba7db43759c8c6f9e03ff2f25bc0ac43ca 100644
--- a/src/core/SkStream.cpp
+++ b/src/core/SkStream.cpp
@@ -367,6 +367,20 @@ size_t SkMemoryStream::read(void* buffer, size_t size) {
return size;
}
+bool SkMemoryStream::peek(void* buffer, size_t size) const {
+ SkASSERT(buffer != NULL);
+ const size_t position = fOffset;
+ if (size > fData->size() - position) {
+ // The stream is not large enough to satisfy this request.
+ return false;
+ }
+ SkMemoryStream* nonConstThis = const_cast<SkMemoryStream*>(this);
+ SkDEBUGCODE(const size_t bytesRead =) nonConstThis->read(buffer, size);
+ SkASSERT(bytesRead == size);
+ nonConstThis->fOffset = position;
+ return true;
+}
+
bool SkMemoryStream::isAtEnd() const {
return fOffset == fData->size();
}
« no previous file with comments | « include/core/SkStream.h ('k') | src/utils/SkFrontBufferedStream.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698