-
Notifications
You must be signed in to change notification settings - Fork 10
Add pledgeinsize
#64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add pledgeinsize
#64
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
11cff42
Add pledgeinsize
nhz2 9f89a86
Merge branch 'master' into nz-pledgeinsize
nhz2 04e818f
Merge branch 'master' into nz-pledgeinsize
nhz2 e0c0238
Add tests for pledgeinsize
nhz2 b2c4e97
test errors
nhz2 783ecc9
Add coverage for upstream tests
nhz2 e1f070b
test unknown pledgeinsize
nhz2 2a5b290
fix tests for 32 bit
nhz2 0e13c10
remove dead code
nhz2 055af7b
bump compat
nhz2 d635a0b
Merge branch 'master' into nz-pledgeinsize
nhz2 6d9dab0
remove unrelated changes
nhz2 8fd426b
check if `pledgeinsize` is defined
nhz2 40eea70
remove unrelated changes
nhz2 db69f63
fix tests
nhz2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -130,9 +130,17 @@ include("utils.jl") | |
| @test CodecZstd.find_decompressed_size(v) == 22 | ||
|
|
||
| codec = ZstdCompressor | ||
| buffer3 = transcode(codec, b"Hello") | ||
| buffer4 = transcode(codec, b"World!") | ||
| sink = IOBuffer() | ||
| s = TranscodingStream(codec(), sink; stop_on_end=true) | ||
| write(s, b"Hello") | ||
| close(s) | ||
| buffer3 = take!(sink) | ||
| @test CodecZstd.find_decompressed_size(buffer3) == CodecZstd.ZSTD_CONTENTSIZE_UNKNOWN | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| sink = IOBuffer() | ||
| s = TranscodingStream(codec(), sink; stop_on_end=true) | ||
| write(s, b"Hello") | ||
| close(s) | ||
| buffer4 = take!(sink) | ||
| @test CodecZstd.find_decompressed_size(buffer4) == CodecZstd.ZSTD_CONTENTSIZE_UNKNOWN | ||
|
|
||
| write(iob, buffer1) | ||
|
|
@@ -156,6 +164,68 @@ include("utils.jl") | |
| @test CodecZstd.find_decompressed_size(v) == CodecZstd.ZSTD_CONTENTSIZE_ERROR | ||
| end | ||
|
|
||
| if isdefined(TranscodingStreams, :pledgeinsize) | ||
| @testset "pledgeinsize" begin | ||
| # when pledgeinsize is available transcode should save the | ||
| # decompressed size in a header | ||
| for n in [0:30; 1000; 1000000;] | ||
| v = transcode(ZstdCompressor, rand(UInt8, n)) | ||
| @test CodecZstd.find_decompressed_size(v) == n | ||
| end | ||
|
|
||
| # Test what happens if pledgeinsize promise is broken | ||
| d1 = zeros(UInt8, 10000) | ||
| d2 = zeros(UInt8, 10000) | ||
| GC.@preserve d1 d2 begin | ||
| @testset "too many bytes" begin | ||
| m1 = TranscodingStreams.Memory(pointer(d1), 1000) | ||
| m2 = TranscodingStreams.Memory(pointer(d2), 1000) | ||
| codec = ZstdCompressor() | ||
| e = TranscodingStreams.Error() | ||
| @test TranscodingStreams.startproc(codec, :read, e) === :ok | ||
| @test TranscodingStreams.pledgeinsize(codec, Int64(10), e) === :ok | ||
| @test TranscodingStreams.process(codec, m1, m2, e) === (0, 0, :error) | ||
| @test e[] == ErrorException("zstd compression error: Src size is incorrect") | ||
| TranscodingStreams.finalize(codec) | ||
| end | ||
| @testset "too few bytes" begin | ||
| m1 = TranscodingStreams.Memory(pointer(d1), 10) | ||
| m2 = TranscodingStreams.Memory(pointer(d2), 1000) | ||
| codec = ZstdCompressor() | ||
| e = TranscodingStreams.Error() | ||
| @test TranscodingStreams.startproc(codec, :read, e) === :ok | ||
| @test TranscodingStreams.pledgeinsize(codec, Int64(10000), e) === :ok | ||
| @test TranscodingStreams.process(codec, m1, m2, e)[3] === :ok | ||
| m1 = TranscodingStreams.Memory(pointer(d1), 0) | ||
| @test TranscodingStreams.process(codec, m1, m2, e)[3] === :error | ||
| @test e[] == ErrorException("zstd compression error: Src size is incorrect") | ||
| TranscodingStreams.finalize(codec) | ||
| end | ||
| @testset "set pledgeinsize after process" begin | ||
| m1 = TranscodingStreams.Memory(pointer(d1), 1000) | ||
| m2 = TranscodingStreams.Memory(pointer(d2), 1000) | ||
| codec = ZstdCompressor() | ||
| e = TranscodingStreams.Error() | ||
| @test TranscodingStreams.startproc(codec, :read, e) === :ok | ||
| @test TranscodingStreams.process(codec, m1, m2, e)[3] === :ok | ||
| @test TranscodingStreams.pledgeinsize(codec, Int64(10000), e) === :error | ||
| @test e[] == ErrorException("zstd error setting pledged source size") | ||
| TranscodingStreams.finalize(codec) | ||
| end | ||
| @testset "set unknown pledgeinsize" begin | ||
| m1 = TranscodingStreams.Memory(pointer(d1), 1000) | ||
| m2 = TranscodingStreams.Memory(pointer(d2), 1000) | ||
| codec = ZstdCompressor() | ||
| e = TranscodingStreams.Error() | ||
| @test TranscodingStreams.startproc(codec, :read, e) === :ok | ||
| @test TranscodingStreams.pledgeinsize(codec, Int64(-1), e) === :ok | ||
| @test TranscodingStreams.process(codec, m1, m2, e)[3] === :ok | ||
| TranscodingStreams.finalize(codec) | ||
| end | ||
| end | ||
| end | ||
| end | ||
|
|
||
| include("compress_endOp.jl") | ||
| include("static_only_tests.jl") | ||
|
|
||
|
|
@@ -195,6 +265,10 @@ include("utils.jl") | |
| TranscodingStreams.finalize(codec) | ||
| data = [0x00,0x01] | ||
| GC.@preserve data let m = TranscodingStreams.Memory(pointer(data), length(data)) | ||
| try | ||
| TranscodingStreams.pledgeinsize(codec, Int64(10), TranscodingStreams.Error()) | ||
| catch | ||
| end | ||
| try | ||
| TranscodingStreams.expectedsize(codec, m) | ||
| catch | ||
|
|
||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.