From 40d02ddf20b9d3ee76f7e6c6ecb428efc5f1102a Mon Sep 17 00:00:00 2001 From: nhz2 Date: Mon, 22 Jul 2024 17:43:28 -0400 Subject: [PATCH] work on fixing buffering --- src/stream.jl | 30 ++++++++++++++++++++++++++++++ test/runtests.jl | 3 +++ 2 files changed, 33 insertions(+) diff --git a/src/stream.jl b/src/stream.jl index e19c166..24c027b 100644 --- a/src/stream.jl +++ b/src/stream.jl @@ -82,6 +82,9 @@ function main_run!(all_in::Bool, input::TranscodingStreams.Memory, output::Trans end run!(s) if all_in + # @info "all in run" + # @show in_length(s) + # @show n_available if in_length(s) > n_available error("not enough bytes available") end @@ -268,6 +271,33 @@ function consume!(s::StreamState, n::UInt8) nothing end +""" + Parse the dynamic huffman tree. + +If 0 is returned: success +sets `s.lit_tree` and `s.dist_tree`. +the read and buffered positions will be updated. + +If -1 is returned: not enough bits +failed to parse the trees because there is not enough bits. +read position is not updated, but buffered position is updated. + +If -2 is returned: clen_tree is invalid. +`s` is invalid and must be reset. + +If -3 is returned: lit_tree is invalid. +`s` is invalid and must be reset. + +If -4 is returned: dist_tree is invalid. +`s` is invalid and must be reset. + + + + +""" +function parse_dynamic_huffman!() +end + function parse_num_bits_per_op!( num_bits_per_op::Vector{UInt8}, N::UInt16, diff --git a/test/runtests.jl b/test/runtests.jl index 8765fa5..524fd24 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -22,10 +22,12 @@ include("tests_from_inflate.jl") @test decompress(zlib_compress(d)) == d @test decompress(p7zip_compress(d)) == d @test de64compress(p7zip_64compress(d)) == d + @test_throws ErrorException de64compress(p7zip_64compress(d)[begin:end-1]) for n in 65536-1000:65536+1000 d = [thing; zeros(UInt8, n); thing] @test decompress(p7zip_64compress(d)) == d + @test_throws ErrorException de64compress(p7zip_64compress(d)[begin:end-1]) end for n in [0:1000; 1000000;] @@ -33,6 +35,7 @@ include("tests_from_inflate.jl") @test decompress(zlib_compress(d)) == d @test decompress(p7zip_compress(d)) == d @test de64compress(p7zip_64compress(d)) == d + @test_throws ErrorException de64compress(p7zip_64compress(d)[begin:end-1]) end end