Skip to content

Latest commit

 

History

History
29 lines (20 loc) · 685 Bytes

README.rst

File metadata and controls

29 lines (20 loc) · 685 Bytes

streamcat

Examples

Encoding a JSON iterator into a stream:

def gen_records():
    yield b'{"foo": "bar"}'
    yield b'{"baz": [1, 2, 3]}'

stream = streamcat.iterator_to_stream(gen_records())

# `stream` can then be used just like any other `io.RawIOBase`
with open('/tmp/jsoncat', 'wb') as destination:
    shutil.copyfileobj(stream, destination)

Decoding a stream into a generator:

decoder = json.JSONDecoder()
with open('/tmp/jsoncat', 'rb') as source:
    records = streamcat.stream_to_iterator(source, decoder)
    for record in records:
        print(record)