Repository navigation
Add ZSTD file access API (fopen/fread/fwrite/fclose) - #4797
ceedot-rock wants to merge 1 commit into
Conversation
|
Hi @ceedot-rock! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
…close) Implements meta#199: gzopen-style wrappers that compress, buffer, and talk to the filesystem. Purely additive on top of ZSTD_compressStream2 / ZSTD_decompressStream plus stdio; files are plain zstd frames, so the zstd CLI reads what the API writes and vice versa. - New lib/compress/zstd_file.c, picked up by the existing wildcard builds (make, cmake, buck); symbols export from the shared lib. - API + error semantics documented in lib/zstd.h. - New tests/fileApiTest.c wired into tests/Makefile (test-fileapi, also part of 'make test'): roundtrips, CLI interop both ways, error paths, fclose flush, levels. 59 checks, all passing.
e0668a2 to
23521bd
Compare
Closes #199.
Adds the file convenience API this issue has asked for since 2016: an opaque ZSTD_FCtx with ZSTD_fopen(path, mode) / ZSTD_fopenLevel(path, mode, level), ZSTD_fread, ZSTD_fwrite, ZSTD_fclose, plus ZSTD_ferror() as a sticky error query (the gzerror parallel).
Built on the streaming API plus stdio, so the codec itself is untouched. Modes are r/w (b/t accepted and ignored); anything else, including append, fails cleanly. Deliberately the core six of zlib's ~20: no append, no fdopen, no seek, no dict support in this cut - easy to extend later without breaking the API.
Design notes for review: fclose returns 0 on success, otherwise the sticky ZSTD_ErrorCode; fwrite is all-or-nothing rather than partial counts; I/O errors collapse to ZSTD_error_GENERIC.
Tests: new tests/fileApiTest.c, 59 checks, 0 failures - text and 3MB binary roundtrips, odd chunk sizes, 1-byte stress, empty payloads, EOF semantics, levels 1/19/negative/clamped, full error-path matrix. Output decompresses with the zstd CLI and vice versa. ASan/UBSan clean, 500 fuzzer iterations clean.
Slid Phi Labs accepts donations to keep the lab independent.