1 def yield_lines(iterable):
2 """Converts an arbitrary bytes iterable into an iterable that yields whole
3 lines. The final byte of each returned value (except possibly the last one)
4 is a newline or carriage return character. The concatenation of the input
5 iterable equals the concatenation of the output iterable."""
9 parts = buff.splitlines(True)
15 def decompress_stream(iterable, decompressor):
16 """Decompress an iterable of bytes using the given decompressor into
17 another (decompressed) iterable of bytes. The decompressor can be a
18 bz2.BZ2Decompressor or lzma.LZMADecompressor instance."""
20 data = decompressor.decompress(data)
22 if hasattr(decompressor, "flush"):
23 yield decompressor.flush()
25 def yield_chunks(filelike, chunksize=65536):
26 """Read the given file in chunks of the given size. Returns an itrable
27 of contents. If the file is binary, it yields bytes, otherwise str."""
29 data = filelike.read(chunksize)