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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 """Small helper class to provide a small slice of a stream."""
2
3 from gslib.third_party.storage_apitools import exceptions
4
5 class StreamSlice(object):
6
7 def __init__(self, stream, max_bytes):
8 self.__stream = stream
9 self.__remaining_bytes = max_bytes
10 self.__max_bytes = max_bytes
11
12 def __str__(self):
13 return 'Slice of stream %s with %s/%s bytes not yet read' % (
14 self.__stream, self.__remaining_bytes, self.__max_bytes)
15
16 def __len__(self):
17 return self.__max_bytes
18
19 def read(self, size=None):
20 if size is not None:
21 size = min(size, self.__remaining_bytes)
22 else:
23 size = self.__remaining_bytes
24 data = self.__stream.read(size)
25 if not data and self.__remaining_bytes:
26 raise exceptions.TransferInvalidError(
27 'Not enough bytes in stream; expected %d, stream exhasted after %d' % (
28 self.__max_bytes, self.__remaining_bytes))
29 self.__remaining_bytes -= len(data)
30 return data
OLDNEW
« 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