跳转到主要内容

将连接对象编码和解码为流

项目描述

将JSON迭代器编码为流

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)

将流解码为生成器

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

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源分布

streamcat-0.2.1.tar.gz (4.1 kB 查看哈希)

上传时间:

构建分布

streamcat-0.2.1-py2.py3-none-any.whl (3.7 kB 查看哈希)

上传时间: Python 2 Python 3

由以下支持

AWSAWS云计算和安全赞助商DatadogDatadog监控FastlyFastlyCDNGoogleGoogle下载分析MicrosoftMicrosoftPSF赞助商PingdomPingdom监控SentrySentry错误日志StatusPageStatusPage状态页面