Skip to content

Commit

Permalink
work on fixing buffering
Browse files Browse the repository at this point in the history
  • Loading branch information
nhz2 committed Jul 22, 2024
1 parent 8572d38 commit 40d02dd
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/stream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,20 @@ 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;]
d = zeros(UInt8, n)
@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

Expand Down

0 comments on commit 40d02dd

Please sign in to comment.