Skip to content

Commit c784f24

Browse files
authored
Rename compressors and decompressors (#5)
1 parent 91bac86 commit c784f24

File tree

5 files changed

+63
-57
lines changed

5 files changed

+63
-57
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,24 @@ erat ex bibendum ipsum, sed varius ipsum ipsum vitae dui.
2727
"""
2828

2929
# Streaming API.
30-
stream = ZstdCompressionStream(IOBuffer(text))
31-
for line in eachline(ZstdDecompressionStream(stream))
30+
stream = ZstdCompressorStream(IOBuffer(text))
31+
for line in eachline(ZstdDecompressorStream(stream))
3232
println(line)
3333
end
3434
close(stream)
3535

3636
# Array API.
37-
compressed = transcode(ZstdCompression(), text)
37+
compressed = transcode(ZstdCompressor, text)
3838
@assert sizeof(compressed) < sizeof(text)
39-
@assert transcode(ZstdDecompression(), compressed) == Vector{UInt8}(text)
39+
@assert transcode(ZstdDecompressor, compressed) == Vector{UInt8}(text)
4040
```
4141

4242
This package exports following codecs and streams:
4343

44-
| Codec | Stream |
45-
| ------------------- | ------------------------- |
46-
| `ZstdCompression` | `ZstdCompressionStream` |
47-
| `ZstdDecompression` | `ZstdDecompressionStream` |
44+
| Codec | Stream |
45+
| ------------------ | ------------------------ |
46+
| `ZstdCompressor` | `ZstdCompressorStream` |
47+
| `ZstdDecompressor` | `ZstdDecompressorStream` |
4848

4949
See docstrings and [TranscodingStreams.jl](https://github.com/bicycle1885/TranscodingStreams.jl) for details.
5050

src/CodecZstd.jl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ __precompile__()
33
module CodecZstd
44

55
export
6-
ZstdCompression,
7-
ZstdCompressionStream,
8-
ZstdDecompression,
9-
ZstdDecompressionStream
6+
ZstdCompressor,
7+
ZstdCompressorStream,
8+
ZstdDecompressor,
9+
ZstdDecompressorStream
1010

1111
import TranscodingStreams:
1212
TranscodingStreams,
@@ -20,4 +20,10 @@ include("libzstd.jl")
2020
include("compression.jl")
2121
include("decompression.jl")
2222

23+
# Deprecations
24+
@deprecate ZstdCompression ZstdCompressor
25+
@deprecate ZstdCompressionStream ZstdCompressorStream
26+
@deprecate ZstdDecompression ZstdDecompressor
27+
@deprecate ZstdDecompressionStream ZstdDecompressorStream
28+
2329
end # module

src/compression.jl

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,58 @@
1-
# Compression Codec
2-
# =================
1+
# Compressor Codec
2+
# ================
33

4-
struct ZstdCompression <: TranscodingStreams.Codec
4+
struct ZstdCompressor <: TranscodingStreams.Codec
55
cstream::CStream
66
level::Int
77
end
88

9-
function Base.show(io::IO, codec::ZstdCompression)
9+
function Base.show(io::IO, codec::ZstdCompressor)
1010
print(io, summary(codec), "(level=$(codec.level))")
1111
end
1212

1313
# Same as the zstd command line tool (v1.2.0).
1414
const DEFAULT_COMPRESSION_LEVEL = 3
1515

1616
"""
17-
ZstdCompression(;level=$(DEFAULT_COMPRESSION_LEVEL))
17+
ZstdCompressor(;level=$(DEFAULT_COMPRESSION_LEVEL))
1818
1919
Create a new zstd compression codec.
2020
2121
Arguments
2222
---------
2323
- `level`: compression level (1..$(MAX_CLEVEL))
2424
"""
25-
function ZstdCompression(;level::Integer=DEFAULT_COMPRESSION_LEVEL)
25+
function ZstdCompressor(;level::Integer=DEFAULT_COMPRESSION_LEVEL)
2626
if !(1 level MAX_CLEVEL)
2727
throw(ArgumentError("level must be within 1..$(MAX_CLEVEL)"))
2828
end
29-
return ZstdCompression(CStream(), level)
29+
return ZstdCompressor(CStream(), level)
3030
end
3131

32-
const ZstdCompressionStream{S} = TranscodingStream{ZstdCompression,S} where S<:IO
32+
const ZstdCompressorStream{S} = TranscodingStream{ZstdCompressor,S} where S<:IO
3333

3434
"""
35-
ZstdCompressionStream(stream::IO; kwargs...)
35+
ZstdCompressorStream(stream::IO; kwargs...)
3636
37-
Create a new zstd compression stream (see `ZstdCompression` for `kwargs`).
37+
Create a new zstd compression stream (see `ZstdCompressor` for `kwargs`).
3838
"""
39-
function ZstdCompressionStream(stream::IO; kwargs...)
40-
return TranscodingStream(ZstdCompression(;kwargs...), stream)
39+
function ZstdCompressorStream(stream::IO; kwargs...)
40+
return TranscodingStream(ZstdCompressor(;kwargs...), stream)
4141
end
4242

4343

4444
# Methods
4545
# -------
4646

47-
function TranscodingStreams.initialize(codec::ZstdCompression)
47+
function TranscodingStreams.initialize(codec::ZstdCompressor)
4848
code = initialize!(codec.cstream, codec.level)
4949
if iserror(code)
5050
zstderror(codec.cstream, code)
5151
end
5252
return
5353
end
5454

55-
function TranscodingStreams.finalize(codec::ZstdCompression)
55+
function TranscodingStreams.finalize(codec::ZstdCompressor)
5656
if codec.cstream.ptr != C_NULL
5757
code = free!(codec.cstream)
5858
if iserror(code)
@@ -63,7 +63,7 @@ function TranscodingStreams.finalize(codec::ZstdCompression)
6363
return
6464
end
6565

66-
function TranscodingStreams.startproc(codec::ZstdCompression, mode::Symbol, error::Error)
66+
function TranscodingStreams.startproc(codec::ZstdCompressor, mode::Symbol, error::Error)
6767
code = reset!(codec.cstream, 0 #=unknown source size=#)
6868
if iserror(code)
6969
error[] = ErrorException("zstd error")
@@ -72,7 +72,7 @@ function TranscodingStreams.startproc(codec::ZstdCompression, mode::Symbol, erro
7272
return :ok
7373
end
7474

75-
function TranscodingStreams.process(codec::ZstdCompression, input::Memory, output::Memory, error::Error)
75+
function TranscodingStreams.process(codec::ZstdCompressor, input::Memory, output::Memory, error::Error)
7676
cstream = codec.cstream
7777
cstream.ibuffer.src = input.ptr
7878
cstream.ibuffer.size = input.size

src/decompression.jl

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,47 @@
1-
# Decompression Codec
2-
# ===================
1+
# Decompressor Codec
2+
# ==================
33

4-
struct ZstdDecompression <: TranscodingStreams.Codec
4+
struct ZstdDecompressor <: TranscodingStreams.Codec
55
dstream::DStream
66
end
77

8-
function Base.show(io::IO, codec::ZstdDecompression)
8+
function Base.show(io::IO, codec::ZstdDecompressor)
99
print(io, summary(codec), "()")
1010
end
1111

1212
"""
13-
ZstdDecompression()
13+
ZstdDecompressor()
1414
1515
Create a new zstd decompression codec.
1616
"""
17-
function ZstdDecompression()
18-
return ZstdDecompression(DStream())
17+
function ZstdDecompressor()
18+
return ZstdDecompressor(DStream())
1919
end
2020

21-
const ZstdDecompressionStream{S} = TranscodingStream{ZstdDecompression,S} where S<:IO
21+
const ZstdDecompressorStream{S} = TranscodingStream{ZstdDecompressor,S} where S<:IO
2222

2323
"""
24-
ZstdDecompressionStream(stream::IO)
24+
ZstdDecompressorStream(stream::IO)
2525
2626
Create a new zstd decompression stream.
2727
"""
28-
function ZstdDecompressionStream(stream::IO)
29-
return TranscodingStream(ZstdDecompression(), stream)
28+
function ZstdDecompressorStream(stream::IO)
29+
return TranscodingStream(ZstdDecompressor(), stream)
3030
end
3131

3232

3333
# Methods
3434
# -------
3535

36-
function TranscodingStreams.initialize(codec::ZstdDecompression)
36+
function TranscodingStreams.initialize(codec::ZstdDecompressor)
3737
code = initialize!(codec.dstream)
3838
if iserror(code)
3939
zstderror(codec.dstream, code)
4040
end
4141
return
4242
end
4343

44-
function TranscodingStreams.finalize(codec::ZstdDecompression)
44+
function TranscodingStreams.finalize(codec::ZstdDecompressor)
4545
if codec.dstream.ptr != C_NULL
4646
code = free!(codec.dstream)
4747
if iserror(code)
@@ -52,7 +52,7 @@ function TranscodingStreams.finalize(codec::ZstdDecompression)
5252
return
5353
end
5454

55-
function TranscodingStreams.startproc(codec::ZstdDecompression, mode::Symbol, error::Error)
55+
function TranscodingStreams.startproc(codec::ZstdDecompressor, mode::Symbol, error::Error)
5656
code = reset!(codec.dstream)
5757
if iserror(code)
5858
error[] = ErrorException("zstd error")
@@ -61,7 +61,7 @@ function TranscodingStreams.startproc(codec::ZstdDecompression, mode::Symbol, er
6161
return :ok
6262
end
6363

64-
function TranscodingStreams.process(codec::ZstdDecompression, input::Memory, output::Memory, error::Error)
64+
function TranscodingStreams.process(codec::ZstdDecompressor, input::Memory, output::Memory, error::Error)
6565
dstream = codec.dstream
6666
dstream.ibuffer.src = input.ptr
6767
dstream.ibuffer.size = input.size

test/runtests.jl

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,27 @@ 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))
6+
codec = ZstdCompressor()
7+
@test codec isa ZstdCompressor
8+
@test ismatch(r"^CodecZstd.ZstdCompressor\(level=\d+\)$", sprint(show, codec))
99
@test CodecZstd.initialize(codec) === nothing
1010
@test CodecZstd.finalize(codec) === nothing
1111

12-
codec = ZstdDecompression()
13-
@test codec isa ZstdDecompression
14-
@test ismatch(r"^CodecZstd.ZstdDecompression\(\)$", sprint(show, codec))
12+
codec = ZstdDecompressor()
13+
@test codec isa ZstdDecompressor
14+
@test ismatch(r"^CodecZstd.ZstdDecompressor\(\)$", sprint(show, codec))
1515
@test CodecZstd.initialize(codec) === nothing
1616
@test CodecZstd.finalize(codec) === nothing
1717

1818
data = [0x28, 0xb5, 0x2f, 0xfd, 0x04, 0x50, 0x19, 0x00, 0x00, 0x66, 0x6f, 0x6f, 0x3f, 0xba, 0xc4, 0x59]
19-
@test read(ZstdDecompressionStream(IOBuffer(data))) == b"foo"
20-
@test read(ZstdDecompressionStream(IOBuffer(vcat(data, data)))) == b"foofoo"
19+
@test read(ZstdDecompressorStream(IOBuffer(data))) == b"foo"
20+
@test read(ZstdDecompressorStream(IOBuffer(vcat(data, data)))) == b"foofoo"
2121

22-
@test ZstdCompressionStream <: TranscodingStreams.TranscodingStream
23-
@test ZstdDecompressionStream <: TranscodingStreams.TranscodingStream
22+
@test ZstdCompressorStream <: TranscodingStreams.TranscodingStream
23+
@test ZstdDecompressorStream <: TranscodingStreams.TranscodingStream
2424

25-
TranscodingStreams.test_roundtrip_read(ZstdCompressionStream, ZstdDecompressionStream)
26-
TranscodingStreams.test_roundtrip_write(ZstdCompressionStream, ZstdDecompressionStream)
27-
TranscodingStreams.test_roundtrip_lines(ZstdCompressionStream, ZstdDecompressionStream)
28-
TranscodingStreams.test_roundtrip_transcode(ZstdCompression, ZstdDecompression)
25+
TranscodingStreams.test_roundtrip_read(ZstdCompressorStream, ZstdDecompressorStream)
26+
TranscodingStreams.test_roundtrip_write(ZstdCompressorStream, ZstdDecompressorStream)
27+
TranscodingStreams.test_roundtrip_lines(ZstdCompressorStream, ZstdDecompressorStream)
28+
TranscodingStreams.test_roundtrip_transcode(ZstdCompressor, ZstdDecompressor)
2929
end

0 commit comments

Comments
 (0)