Skip to content

Commit a870e22

Browse files
authored
add show methods (#3)
1 parent c9fddb5 commit a870e22

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

src/CodecZstd.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import TranscodingStreams:
1212
TranscodingStreams,
1313
TranscodingStream,
1414
Memory,
15-
Error
15+
Error,
16+
initialize,
17+
finalize
1618

1719
include("libzstd.jl")
1820
include("compression.jl")

src/compression.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ struct ZstdCompression <: TranscodingStreams.Codec
66
level::Int
77
end
88

9+
function Base.show(io::IO, codec::ZstdCompression)
10+
print(io, summary(codec), "(level=$(codec.level))")
11+
end
12+
913
# Same as the zstd command line tool (v1.2.0).
1014
const DEFAULT_COMPRESSION_LEVEL = 3
1115

src/decompression.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ struct ZstdDecompression <: TranscodingStreams.Codec
55
dstream::DStream
66
end
77

8+
function Base.show(io::IO, codec::ZstdDecompression)
9+
print(io, summary(codec), "()")
10+
end
11+
812
"""
913
ZstdDecompression()
1014

test/runtests.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,18 @@ using Base.Test
33
import TranscodingStreams
44

55
@testset "Zstd Codec" begin
6+
codec = ZstdCompression()
7+
@test codec isa ZstdCompression
8+
@test ismatch(r"^CodecZstd.ZstdCompression\(level=\d+\)$", sprint(show, codec))
9+
@test CodecZstd.initialize(codec) === nothing
10+
@test CodecZstd.finalize(codec) === nothing
11+
12+
codec = ZstdDecompression()
13+
@test codec isa ZstdDecompression
14+
@test ismatch(r"^CodecZstd.ZstdDecompression\(\)$", sprint(show, codec))
15+
@test CodecZstd.initialize(codec) === nothing
16+
@test CodecZstd.finalize(codec) === nothing
17+
618
data = [0x28, 0xb5, 0x2f, 0xfd, 0x04, 0x50, 0x19, 0x00, 0x00, 0x66, 0x6f, 0x6f, 0x3f, 0xba, 0xc4, 0x59]
719
@test read(ZstdDecompressionStream(IOBuffer(data))) == b"foo"
820
@test read(ZstdDecompressionStream(IOBuffer(vcat(data, data)))) == b"foofoo"

0 commit comments

Comments
 (0)