Simplified utils.text.StreamingBuffer.
This commit is contained in:
parent
d093e01ec0
commit
277017aea4
|
@ -280,26 +280,13 @@ def compress_string(s):
|
||||||
return zbuf.getvalue()
|
return zbuf.getvalue()
|
||||||
|
|
||||||
|
|
||||||
class StreamingBuffer:
|
class StreamingBuffer(BytesIO):
|
||||||
def __init__(self):
|
|
||||||
self.vals = []
|
|
||||||
|
|
||||||
def write(self, val):
|
|
||||||
self.vals.append(val)
|
|
||||||
|
|
||||||
def read(self):
|
def read(self):
|
||||||
if not self.vals:
|
ret = self.getvalue()
|
||||||
return b''
|
self.seek(0)
|
||||||
ret = b''.join(self.vals)
|
self.truncate()
|
||||||
self.vals = []
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def flush(self):
|
|
||||||
return
|
|
||||||
|
|
||||||
def close(self):
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
# Like compress_string, but for iterators of strings.
|
# Like compress_string, but for iterators of strings.
|
||||||
def compress_sequence(sequence):
|
def compress_sequence(sequence):
|
||||||
|
|
Loading…
Reference in New Issue