Encoding a JSON iterator into a stream:
defgen_records(): yieldb'{"foo": "bar"}'yieldb'{"baz": [1, 2, 3]}'stream=streamcat.iterator_to_stream(gen_records()) # `stream` can then be used just like any other `io.RawIOBase`withopen('/tmp/jsoncat', 'wb') asdestination: shutil.copyfileobj(stream, destination)Decoding a stream into a generator:
decoder=json.JSONDecoder() withopen('/tmp/jsoncat', 'rb') assource: records=streamcat.stream_to_iterator(source, decoder) forrecordinrecords: print(record)