Repository navigation
Add a way to enable content checksums - #177
Open
vignesh2027 wants to merge 1 commit into
Open
vignesh2027 wants to merge 1 commit into
vignesh2027 wants to merge 1 commit into
Conversation
Frames written by this package never carried the optional 32 bit content checksum, unlike the zstd command line tool. Add CompressLevelChecksum on the package and on Ctx, and Writer.SetChecksum for the streaming API. Decompression already verifies the checksum when a frame has one. The Ctx variant sets its parameters through ZSTD_compress2 after a parameter reset, so the setting does not leak into later CompressLevel calls on the same context. Fixes DataDog#43
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #43.
Frames produced by this package never include the optional content checksum, so compressing an empty slice gives 9 bytes where the zstd command line tool gives 13. This adds a way to turn it on.
New API:
CompressLevelChecksum(dst, src, level)on the package and onCtx, andWriter.SetChecksum(bool)for the streaming API. Existing functions behave exactly as before, so nothing changes unless a caller opts in. Adding the method toCtxdoes break anyone who implements that interface outside the package, the same asDecompressIntodid in #151. If you would rather avoid that, I can move it to a separate optional interface instead. Decompress and the stream Reader already verify the checksum when a frame carries one.The
Ctxvariant goes throughZSTD_compress2after a parameter reset, becauseZSTD_compressCCtxignores advanced parameters. A test checks that a laterCompressLevelcall on the same context still produces a frame without a checksum.Tests cover the 13 byte empty frame from the issue, round trips, the 4 byte size difference, corruption of the checksum being rejected by Decompress, Ctx and the stream Reader, and toggling the setting back off. Full suite passes with
-race.