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

Unified Diff: gslib/third_party/storage_apitools/stream_slice.py

Issue 698893003: Update checked in version of gsutil to version 4.6 (Closed) Base URL: http://dart.googlecode.com/svn/third_party/gsutil/
Patch Set: Created 6 years, 1 month 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: gslib/third_party/storage_apitools/stream_slice.py
===================================================================
--- gslib/third_party/storage_apitools/stream_slice.py (revision 0)
+++ gslib/third_party/storage_apitools/stream_slice.py (revision 0)
@@ -0,0 +1,30 @@
+"""Small helper class to provide a small slice of a stream."""
+
+from gslib.third_party.storage_apitools import exceptions
+
+class StreamSlice(object):
+
+ def __init__(self, stream, max_bytes):
+ self.__stream = stream
+ self.__remaining_bytes = max_bytes
+ self.__max_bytes = max_bytes
+
+ def __str__(self):
+ return 'Slice of stream %s with %s/%s bytes not yet read' % (
+ self.__stream, self.__remaining_bytes, self.__max_bytes)
+
+ def __len__(self):
+ return self.__max_bytes
+
+ def read(self, size=None):
+ if size is not None:
+ size = min(size, self.__remaining_bytes)
+ else:
+ size = self.__remaining_bytes
+ data = self.__stream.read(size)
+ if not data and self.__remaining_bytes:
+ raise exceptions.TransferInvalidError(
+ 'Not enough bytes in stream; expected %d, stream exhasted after %d' % (
+ self.__max_bytes, self.__remaining_bytes))
+ self.__remaining_bytes -= len(data)
+ return data
Property changes on: gslib/third_party/storage_apitools/stream_slice.py
___________________________________________________________________
Added: svn:eol-style
+ LF
« no previous file with comments | « gslib/third_party/storage_apitools/storage_v1_messages.py ('k') | gslib/third_party/storage_apitools/transfer.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698