Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/.vscode/

Manifest.toml
Manifest-*.toml
fixture.tar.gz
fixture
.CondaPkg
Expand Down
2 changes: 2 additions & 0 deletions ChunkCodecCore/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## Unreleased

### BREAKING `can_concatenate` is now a decoder method instead of a `Codec` method [#73](https://github.com/JuliaIO/ChunkCodecs.jl/pull/73)

### BREAKING the return type of `try_encode`, `try_decode`, and `try_resize_decode!` changed to a new `MaybeSize` type [#72](https://github.com/JuliaIO/ChunkCodecs.jl/pull/72)

## [v0.5.3](https://github.com/JuliaIO/ChunkCodecs.jl/tree/ChunkCodecCore-v0.5.3) - 2025-08-09
Expand Down
23 changes: 12 additions & 11 deletions ChunkCodecCore/src/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,6 @@ Return the default decode options for the codec.
"""
function decode_options end

"""
can_concatenate(::Codec)::Bool

Return `true` if the codec has concatenation transparency.

If `true`, and some encoded data `a` and `b` decode to `x` and `y` respectively, then
the concatenation of `a` and `b` will
decode to the concatenation of `x` and `y`
"""
can_concatenate(::Codec) = false

"""
decoded_size_range(e)::StepRange{Int64, Int64}

Expand Down Expand Up @@ -258,10 +247,22 @@ function try_resize_decode!(d, dst::AbstractVector{UInt8}, src::AbstractVector{U
end
end

"""
can_concatenate(d)::Bool

Return `true` if the decoder has concatenation transparency.

If `true`, and some encoded data `a` and `b` decode to `x` and `y` respectively, then
the concatenation of `a` and `b` will
decode to the concatenation of `x` and `y`
"""
can_concatenate(::Any) = false

# allow passing codec to decode
try_find_decoded_size(c::Codec, src::AbstractVector{UInt8}) = try_find_decoded_size(decode_options(c), src)
try_decode!(c::Codec, dst::AbstractVector{UInt8}, src::AbstractVector{UInt8}; kwargs...) = try_decode!(decode_options(c), dst, src; kwargs...)
try_resize_decode!(c::Codec, dst::AbstractVector{UInt8}, src::AbstractVector{UInt8}, max_size::Int64; kwargs...) = try_resize_decode!(decode_options(c), dst, src, max_size; kwargs...)
can_concatenate(c::Codec) = can_concatenate(decode_options(c))

"""
check_contiguous(x::AbstractVector{UInt8})
Expand Down
3 changes: 2 additions & 1 deletion ChunkCodecCore/src/noop.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ Copies the input.
See also [`NoopEncodeOptions`](@ref) and [`NoopDecodeOptions`](@ref)
"""
struct NoopCodec <: Codec end
can_concatenate(::NoopCodec) = true
decode_options(::NoopCodec) = NoopDecodeOptions() # default decode options

"""
Expand Down Expand Up @@ -72,6 +71,8 @@ end

is_thread_safe(::NoopDecodeOptions) = true

can_concatenate(::NoopDecodeOptions) = true

function try_find_decoded_size(::NoopDecodeOptions, src::AbstractVector{UInt8})::Int64
length(src)
end
Expand Down
4 changes: 1 addition & 3 deletions ChunkCodecCore/src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ Properties are public for reading.

Required methods for a type `T <: Codec` to implement:
- `decode_options(::T)::DecodeOptions`

Optional methods to implement:
- `can_concatenate(::T)::Bool`: defaults to `false`.
"""
abstract type Codec end

Expand Down Expand Up @@ -51,6 +48,7 @@ Required methods for a type `T <: DecodeOptions` to implement:

Optional methods to implement:
- `is_thread_safe(::T)::Bool`: defaults to `false`.
- `can_concatenate(::T)::Bool`: defaults to `false`.
- `try_resize_decode!(::T, dst::AbstractVector{UInt8}, src::AbstractVector{UInt8}, max_size::Int64; kwargs...)::MaybeSize`: defaults to using `try_decode!` and `try_find_decoded_size`
"""
abstract type DecodeOptions end
2 changes: 1 addition & 1 deletion ChunkCodecTests/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## Unreleased

- Update to `ChunkCodecCore` 0.6 [#72](https://github.com/JuliaIO/ChunkCodecs.jl/pull/72)
- Update to `ChunkCodecCore` 0.6 [#72](https://github.com/JuliaIO/ChunkCodecs.jl/pull/72) [#73](https://github.com/JuliaIO/ChunkCodecs.jl/pull/73)
- Added support for Julia 1.6 [#68](https://github.com/JuliaIO/ChunkCodecs.jl/pull/68)

## [v0.1.5](https://github.com/JuliaIO/ChunkCodecs.jl/tree/ChunkCodecTests-v0.1.5) - 2025-07-28
Expand Down
19 changes: 10 additions & 9 deletions ChunkCodecTests/src/ChunkCodecTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export test_codec, test_encoder_decoder, rand_test_data
function test_codec(c::Codec, e::EncodeOptions, d::DecodeOptions; trials=100)
@test decode_options(c) isa DecodeOptions
@test can_concatenate(c) isa Bool
@test can_concatenate(d) isa Bool
@test e.codec == c
@test d.codec == c
@test is_thread_safe(e) isa Bool
Expand All @@ -39,15 +40,6 @@ function test_codec(c::Codec, e::EncodeOptions, d::DecodeOptions; trials=100)
@test typeof(d)(;NamedTuple{d_props}(getproperty.((d,), d_props))...) == d

test_encoder_decoder(e, d; trials)

# can_concatenate tests
if can_concatenate(c)
srange = decoded_size_range(e)
a = rand(UInt8, 100*step(srange))
b = rand(UInt8, 200*step(srange))
@test decode(d, [encode(e, a); encode(e, b);]) == [a; b;]
@test decode(d, [encode(e, UInt8[]); encode(e, UInt8[]);]) == UInt8[]
end
end

function test_encoder_decoder(e, d; trials=100)
Expand Down Expand Up @@ -141,6 +133,15 @@ function test_encoder_decoder(e, d; trials=100)

@test decode(d, encoded) == data
end

# can_concatenate tests
if can_concatenate(d)
srange = decoded_size_range(e)
a = rand(UInt8, 100*step(srange))
b = rand(UInt8, 200*step(srange))
@test decode(d, [encode(e, a); encode(e, b);]) == [a; b;]
@test decode(d, [encode(e, UInt8[]); encode(e, UInt8[]);]) == UInt8[]
end
end

function rand_test_data(s::Int64)::Vector{UInt8}
Expand Down
2 changes: 1 addition & 1 deletion LibBzip2/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## Unreleased

- Update to `ChunkCodecCore` 0.6 [#72](https://github.com/JuliaIO/ChunkCodecs.jl/pull/72)
- Update to `ChunkCodecCore` 0.6 [#72](https://github.com/JuliaIO/ChunkCodecs.jl/pull/72) [#73](https://github.com/JuliaIO/ChunkCodecs.jl/pull/73)
- Added support for Julia 1.6 [#68](https://github.com/JuliaIO/ChunkCodecs.jl/pull/68)

## [v0.2.1](https://github.com/JuliaIO/ChunkCodecs.jl/tree/LibBzip2-v0.2.1) - 2025-07-28
Expand Down
2 changes: 0 additions & 2 deletions LibBzip2/src/ChunkCodecLibBzip2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ struct BZ2Codec <: Codec
end
decode_options(::BZ2Codec) = BZ2DecodeOptions()

can_concatenate(::BZ2Codec) = true

include("encode.jl")
include("decode.jl")

Expand Down
1 change: 1 addition & 0 deletions LibBzip2/src/decode.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ function BZ2DecodeOptions(;
BZ2DecodeOptions(codec)
end
is_thread_safe(::BZ2DecodeOptions) = true
can_concatenate(::BZ2DecodeOptions) = true

function try_find_decoded_size(::BZ2DecodeOptions, src::AbstractVector{UInt8})::Nothing
nothing
Expand Down
2 changes: 1 addition & 1 deletion LibLz4/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## Unreleased

- Update to `ChunkCodecCore` 0.6 [#72](https://github.com/JuliaIO/ChunkCodecs.jl/pull/72)
- Update to `ChunkCodecCore` 0.6 [#72](https://github.com/JuliaIO/ChunkCodecs.jl/pull/72) [#73](https://github.com/JuliaIO/ChunkCodecs.jl/pull/73)
- Added support for Julia 1.6 [#68](https://github.com/JuliaIO/ChunkCodecs.jl/pull/68)

## [v0.2.2](https://github.com/JuliaIO/ChunkCodecs.jl/tree/LibLz4-v0.2.2) - 2025-07-28
Expand Down
1 change: 0 additions & 1 deletion LibLz4/src/ChunkCodecLibLz4.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ See also [`LZ4FrameEncodeOptions`](@ref) and [`LZ4FrameDecodeOptions`](@ref)
struct LZ4FrameCodec <: Codec
end
decode_options(::LZ4FrameCodec) = LZ4FrameDecodeOptions() # default decode options
can_concatenate(::LZ4FrameCodec) = true

"""
struct LZ4BlockCodec <: Codec
Expand Down
2 changes: 2 additions & 0 deletions LibLz4/src/decode.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ end

is_thread_safe(::LZ4FrameDecodeOptions) = true

can_concatenate(::LZ4FrameDecodeOptions) = true

function try_find_decoded_size(::LZ4FrameDecodeOptions, src::AbstractVector{UInt8})::Nothing
# TODO This might be possible to do using a method similar to ZstdDecodeOptions
# For now just return nothing
Expand Down
2 changes: 1 addition & 1 deletion LibZlib/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## Unreleased

- Update to `ChunkCodecCore` 0.6 [#72](https://github.com/JuliaIO/ChunkCodecs.jl/pull/72)
- Update to `ChunkCodecCore` 0.6 [#72](https://github.com/JuliaIO/ChunkCodecs.jl/pull/72) [#73](https://github.com/JuliaIO/ChunkCodecs.jl/pull/73)
- Added support for Julia 1.6 [#68](https://github.com/JuliaIO/ChunkCodecs.jl/pull/68)

## [v0.2.1](https://github.com/JuliaIO/ChunkCodecs.jl/tree/LibZlib-v0.2.1) - 2025-07-28
Expand Down
8 changes: 5 additions & 3 deletions LibZlib/src/decode.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ function GzipDecodeOptions(;
GzipDecodeOptions(codec)
end

can_concatenate(::GzipDecodeOptions) = true

const _AllDecodeOptions = Union{ZlibDecodeOptions, DeflateDecodeOptions, GzipDecodeOptions}

is_thread_safe(::_AllDecodeOptions) = true
Expand All @@ -103,7 +105,7 @@ function try_resize_decode!(d::_AllDecodeOptions, dst::AbstractVector{UInt8}, sr
end
cconv_src = Base.cconvert(Ptr{UInt8}, src)
# This outer loop is to decode a concatenation of multiple compressed streams.
# If `can_concatenate(d.codec)` is false, this outer loop doesn't rerun.
# If `can_concatenate(d)` is false, this outer loop doesn't rerun.
while true
stream = ZStream()
inflateInit2(stream, _windowBits(d.codec))
Expand Down Expand Up @@ -166,8 +168,8 @@ function try_resize_decode!(d::_AllDecodeOptions, dst::AbstractVector{UInt8}, sr
@assert real_dst_size ∈ 0:length(dst)
return real_dst_size
else
if can_concatenate(d.codec)
# try and decompress next stream if the codec can_concatenate
if can_concatenate(d)
# try and decompress next stream if the decoder can_concatenate
# there must be progress
@assert stream.avail_in < start_avail_in || stream.avail_out < start_avail_out
break
Expand Down
2 changes: 1 addition & 1 deletion LibZstd/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## Unreleased

- Update to `ChunkCodecCore` 0.6 [#72](https://github.com/JuliaIO/ChunkCodecs.jl/pull/72)
- Update to `ChunkCodecCore` 0.6 [#72](https://github.com/JuliaIO/ChunkCodecs.jl/pull/72) [#73](https://github.com/JuliaIO/ChunkCodecs.jl/pull/73)
- Added support for Julia 1.6 [#68](https://github.com/JuliaIO/ChunkCodecs.jl/pull/68)

## [v0.2.1](https://github.com/JuliaIO/ChunkCodecs.jl/tree/LibZstd-v0.2.1) - 2025-07-28
Expand Down
1 change: 0 additions & 1 deletion LibZstd/src/ChunkCodecLibZstd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ See also [`ZstdEncodeOptions`](@ref) and [`ZstdDecodeOptions`](@ref)
struct ZstdCodec <: Codec
end
decode_options(::ZstdCodec) = ZstdDecodeOptions()
can_concatenate(::ZstdCodec) = true

include("encode.jl")
include("decode.jl")
Expand Down
2 changes: 2 additions & 0 deletions LibZstd/src/decode.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ end

is_thread_safe(::ZstdDecodeOptions) = true

can_concatenate(::ZstdDecodeOptions) = true

# find_decompressed_size is modified from CodecZstd.jl
# https://github.com/JuliaIO/CodecZstd.jl/blob/2f7d084b8b157d83ed85e9d15105f0a708038e45/src/libzstd.jl#L157C1-L215C4
# From mkitti's PR https://github.com/JuliaIO/CodecZstd.jl/pull/63
Expand Down
Loading