Skip to content

Commit

Permalink
make stream types a subtype of TranscodingStream (fix d7a7a80)
Browse files Browse the repository at this point in the history
  • Loading branch information
bicycle1885 committed Jun 11, 2017
1 parent 7fc1bca commit 1628c7d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/compression.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function GzipCompression(;level::Integer=Z_DEFAULT_COMPRESSION,
return GzipCompression(ZStream(), level, windowbits+16)
end

const GzipCompressionStream{S} = TranscodingStream{GzipCompression,S}
const GzipCompressionStream{S} = TranscodingStream{GzipCompression,S} where S<:IO

"""
GzipCompressionStream(stream::IO; kwargs...)
Expand Down Expand Up @@ -74,7 +74,7 @@ function ZlibCompression(;level::Integer=Z_DEFAULT_COMPRESSION,
return ZlibCompression(ZStream(), level, windowbits)
end

const ZlibCompressionStream{S} = TranscodingStream{ZlibCompression,S}
const ZlibCompressionStream{S} = TranscodingStream{ZlibCompression,S} where S<:IO

"""
ZlibCompressionStream(stream::IO)
Expand Down Expand Up @@ -115,7 +115,7 @@ function DeflateCompression(;level::Integer=Z_DEFAULT_COMPRESSION,
return DeflateCompression(ZStream(), level, -Int(windowbits))
end

const DeflateCompressionStream{S} = TranscodingStream{DeflateCompression,S}
const DeflateCompressionStream{S} = TranscodingStream{DeflateCompression,S} where S<:IO

"""
DeflateCompressionStream(stream::IO; kwargs...)
Expand Down
6 changes: 3 additions & 3 deletions src/decompression.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function GzipDecompression(;windowbits::Integer=Z_DEFAULT_WINDOWBITS, gziponly::
return GzipDecompression(ZStream(), windowbits+(gziponly?16:32))
end

const GzipDecompressionStream{S} = TranscodingStream{GzipDecompression,S}
const GzipDecompressionStream{S} = TranscodingStream{GzipDecompression,S} where S<:IO

"""
GzipDecompressionStream(stream::IO; kwargs...)
Expand Down Expand Up @@ -67,7 +67,7 @@ function ZlibDecompression(;windowbits::Integer=Z_DEFAULT_WINDOWBITS)
return ZlibDecompression(ZStream(), windowbits)
end

const ZlibDecompressionStream{S} = TranscodingStream{ZlibDecompression,S}
const ZlibDecompressionStream{S} = TranscodingStream{ZlibDecompression,S} where S<:IO

"""
ZlibDecompressionStream(stream::IO; kwargs...)
Expand Down Expand Up @@ -103,7 +103,7 @@ function DeflateDecompression(;windowbits::Integer=Z_DEFAULT_WINDOWBITS)
return DeflateDecompression(ZStream(), -Int(windowbits))
end

const DeflateDecompressionStream{S} = TranscodingStream{DeflateDecompression,S}
const DeflateDecompressionStream{S} = TranscodingStream{DeflateDecompression,S} where S<:IO

"""
DeflateDecompressionStream(stream::IO; kwargs...)
Expand Down
9 changes: 9 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ const testdir = dirname(@__FILE__)
@test length(read(path)) > 0
end

@test GzipCompressionStream <: TranscodingStream
@test GzipDecompressionStream <: TranscodingStream

test_roundtrip_read(GzipCompressionStream, GzipDecompressionStream)
test_roundtrip_write(GzipCompressionStream, GzipDecompressionStream)
test_roundtrip_lines(GzipCompressionStream, GzipDecompressionStream)
Expand Down Expand Up @@ -124,6 +127,9 @@ end
@test read(path) == zlib_data
end

@test ZlibCompressionStream <: TranscodingStream
@test ZlibDecompressionStream <: TranscodingStream

test_roundtrip_read(ZlibCompressionStream, ZlibDecompressionStream)
test_roundtrip_write(ZlibCompressionStream, ZlibDecompressionStream)
test_roundtrip_lines(ZlibCompressionStream, ZlibDecompressionStream)
Expand All @@ -140,6 +146,9 @@ end
test_roundtrip_lines(DeflateCompressionStream, DeflateDecompressionStream)
test_roundtrip_transcode(DeflateCompression, DeflateDecompression)

@test DeflateCompressionStream <: TranscodingStream
@test DeflateDecompressionStream <: TranscodingStream

@test_throws ArgumentError DeflateCompression(level=10)
@test_throws ArgumentError DeflateCompression(windowbits=16)
@test_throws ArgumentError DeflateDecompression(windowbits=16)
Expand Down

0 comments on commit 1628c7d

Please sign in to comment.