-
Notifications
You must be signed in to change notification settings - Fork 14
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
Implement ZstdFrameCompressor via endOp #52
Implement ZstdFrameCompressor via endOp #52
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #52 +/- ##
==========================================
+ Coverage 33.01% 36.96% +3.94%
==========================================
Files 5 5
Lines 524 560 +36
==========================================
+ Hits 173 207 +34
- Misses 351 353 +2 ☔ View full report in Codecov by Sentry. |
I'm getting an zstd error running the following test that the codec supports streaming. using TranscodingStreams
using Test
using CodecZstd
@testset "ZstdFrameCompressor streaming" begin
codec = ZstdFrameCompressor()
TranscodingStreams.initialize(codec)
e = TranscodingStreams.Error()
r = TranscodingStreams.startproc(codec, :write, e)
@test r == :ok
# data buffers
data = rand(UInt8, 32*1024*1024)
buffer1 = copy(data)
buffer2 = zeros(UInt8, length(data)*2)
GC.@preserve buffer1 buffer2 begin
total_out = 0
total_in = 0
while total_in < length(data) || r != :end
in_size = min(length(buffer1) - total_in, 1024*1024)
out_size = min(length(buffer2) - total_out, 1024)
input = TranscodingStreams.Memory(pointer(buffer1, total_in + 1), UInt(in_size))
output = TranscodingStreams.Memory(pointer(buffer2, total_out + 1), UInt(out_size))
Δin, Δout, r = TranscodingStreams.process(codec, input, output, e)
if r == :error
throw(e[])
end
total_out += Δout
total_in += Δin
end
@test r == :end
end
resize!(buffer2, total_out)
@test transcode(ZstdDecompressor, buffer2) == data
end |
The Zstandard error was "Src size is incorrect". I believe this is because we did not the following the protocol for Apparently that protocol means that the input buffer should not change between successive calls to
|
The Julia 1.6 tests on Ubuntu seem a bit flaky to me. I'm not sure what that is about. |
I see the flaw here now. I cannot guaratee the that the input memory before will not be garbage collected. |
In ed3bf8c I started to implement an input buffer. In afabe28, I realized that I do need the input buffer. We just need to keep the input size and position constant if we were not able to output the entire frame at once. To accomplish this without buffering, I just set offset the source pointer back by the last position. Thus no additional copying is required. |
One last question for this PR. Should |
Merging this so we can push forward. I might revisit the type question before release. |
Thank you for the review @nhz2 , I think this is in a substantially better place than where we started. |
Awesome thanks so much!! That's all that was missing to get Zstd into JLD2 right? Then I'll update the pull request there. |
I think at some point we can have |
For JuliaIO/JLD2.jl#560 we'd need a release, would that be possible? |
This was released in 0.8.3 |
Alternate approach to #46. ZstdFrameCompressor is just a ZstdCompressor that has endOp = :end.
With all the available data, the compressor will create and close a frame.
Note there is no
ZstdFrameDecompressor
here.