facebook / facebook/zstd

Multiframe ZSTD file: how to jump to and stream the second file?

Đang mở
#4,569 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
C
Star
27.9k
Fork
2.6k
Merge trung bình
1 ngày 3 giờ
Pull request đã merge (30 ngày)
8

Mô tả

TL;DR: This is not about bugs of ZSTD but about how to take advantage of its feature:

---

I compress two ndjson files into a [multiframe](https://github.com/facebook/zstd/blob/3bee41a70eaf343fbcae3637b3f6edbe52f35ed8/doc/zstd_compression_format.md#frames) ZST file where each ndjson is compressed into a frame. I have the following metadata `meta_data` (as a list) of the ZST file:

````python
import zstandard as zstd
from pathlib import Path

input_file = r"E:\Personal projects\tmp\test.zst"
input_file = Path(output_file)

meta_data = [{'name' : 'chunk_0.ndjson',
'uncompressed_size' : 2147473321,
'compressed_offset' : 0,
'uncompressed_offset' : 0,
'compressed_size' : 175631248},
{'name' : 'chunk_1.ndjson',
'uncompressed_size' : 2147473321,
'compressed_offset' : 175631248,
'uncompressed_offset' : 2147473321,
'compressed_size' : 175631248}]
````

In Python, how can we leverage the above `meta_data` to seek to `chunk_1.ndjson`, start decompressing, and stream it line-by-line? In this way, we don't need to
- decompress `chunk_0.ndjson`,
- load the whole compressed `chunk_1.ndjson` into the memory.

Thank your for your help.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.