An open API service indexing awesome lists of open source software.

https://github.com/cryptosense/streamcat

Encode and decode concatenated objects as streams
https://github.com/cryptosense/streamcat

codec concatenation file-like json python-library streaming

Last synced: about 1 year ago
JSON representation

Encode and decode concatenated objects as streams

Awesome Lists containing this project

README

          

streamcat
=========

Examples
--------

Encoding a JSON iterator into a stream:

.. code-block:: python

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:

.. code-block:: python

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