Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1import io
3import brotli
4import pyarrow as pa
7def compress(array: pa.Array) -> bytes:
8 rb = pa.RecordBatch.from_arrays([array], ["array"])
9 buf = io.BytesIO()
10 writer = pa.RecordBatchFileWriter(buf, rb.schema)
11 writer.write_batch(rb)
12 writer.close()
13 buf.seek(0)
14 return brotli.compress(buf.read())
17def decompress(pybytes: bytes) -> pa.Array:
18 buf = io.BytesIO()
19 buf.write(brotli.decompress(pybytes))
20 buf.seek(0)
21 reader = pa.RecordBatchFileReader(buf)
22 rb = reader.get_batch(0)
23 return rb.column(0)