-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Decompressing with Zstd set bufferSizePrecheck flag to false (#258)
* ZstdNet unwrap false for preCheck size #257 As part of the Unwrap method in ZstdNet it checks if the compressed payload contains the size of the decompressed payload. However it is not a guarrantee that it exists in the compressed payload, causing an exception * Add test case that validates that Zstd with false flag for preSize check works * Update tests/UnitTests/Internal/CompressionCodecTests.fs Co-authored-by: Edgaras Petovradzius <[email protected]> * Update wording in new added test --------- Co-authored-by: Edgaras Petovradzius <[email protected]>
- Loading branch information
Showing
2 changed files
with
20 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ let tests = | |
let helloLZ4 = System.Convert.FromBase64String "UEhlbGxv" | ||
let helloSnappy = System.Convert.FromBase64String "BRBIZWxsbw==" | ||
let helloZStd = System.Convert.FromBase64String "KLUv/SAFKQAASGVsbG8=" | ||
let helloWorldZstdWithoutDecompressedContentSizeInPayload = System.Convert.FromBase64String "KLUv/QBQ/AAAuGhlbGxvIHdvcmxkIGxvcmVtIGlwc3VtAQDN/zWfTUwAAAhpAQD8/zkQAkwAAAhvAQD8/zkQAkwAAAhyAQD8/zkQAkwAAAhsAQD8/zkQAkwAAAh1AQD8/zkQAkwAAAhtAQD8/zkQAkwAAAggAQD8/zkQAkwAAAh3AQD8/zkQAkwAAAhlAQD8/zkQAkwAAAhwAQD8/zkQAkwAAAhyAQD8/zkQAkwAAAhsAQD8/zkQAkwAAAhvAQD8/zkQAkwAAAhtAQD8/zkQAkwAAAggAQD8/zkQAkUAAAhsAQDkKyAE" | ||
|
||
let testEncode compressionType expectedBytes = | ||
let codec = compressionType |> createCodec | ||
|
@@ -79,4 +80,21 @@ let tests = | |
test "Codec should make ZStd decoding" { | ||
helloZStd |> testDecode CompressionType.ZStd | ||
} | ||
|
||
test "Zstd should decode content with non specififed size in the compressed payload" { | ||
// The compressed string above has been compressed with zstd using this library: https://www.npmjs.com/package/[email protected] | ||
// It seems this library does not specify the decompressed size in the payload. | ||
// | ||
// The raw string has been built in JS with the snippet below and then compressed afterwards. | ||
// const bytes = 1024 * 1024 * 2 + 1000 | ||
// let str = ""; | ||
// while (str.length < bytes) | ||
// str += "hello world lorem ipsum" | ||
|
||
let uncompressedSize = (1024 * 1024 * 2 + 1000) | ||
let codec = CompressionType.ZStd |> createCodec | ||
let ms = new MemoryStream(helloWorldZstdWithoutDecompressedContentSizeInPayload, 0, helloWorldZstdWithoutDecompressedContentSizeInPayload.Length, true, true) | ||
let decoded = codec.Decode(uncompressedSize, ms) |> (fun ms -> ms.ToArray())|> getString | ||
decoded |> Expect.stringStarts "" "hello world lorem ipsum" | ||
} | ||
] |