Skip to content

Commit 049144c

Browse files
committed
add buffsize keyword argument
1 parent 39b0361 commit 049144c

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/stream.jl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,18 @@ struct TranscodingStream{C<:Codec,S<:IO} <: IO
3131
end
3232
end
3333

34+
const DEFAULT_BUFFER_SIZE = 16 * 2^10 # 16KiB
35+
3436
"""
35-
TranscodingStream(codec::Codec, stream::IO)
37+
TranscodingStream(codec::Codec, stream::IO; bufsize::Integer=$(DEFAULT_BUFFER_SIZE))
3638
3739
Create a transcoding stream with `codec` and `stream`.
3840
"""
39-
function TranscodingStream(codec::Codec, stream::IO)
40-
return TranscodingStream{typeof(codec),typeof(stream)}(codec, stream, State(16 * 2^10))
41+
function TranscodingStream(codec::Codec, stream::IO; bufsize::Integer=DEFAULT_BUFFER_SIZE)
42+
if bufsize 0
43+
throw(ArgumentError("non-positive buffer size"))
44+
end
45+
return TranscodingStream{typeof(codec),typeof(stream)}(codec, stream, State(bufsize))
4146
end
4247

4348
function Base.show(io::IO, stream::TranscodingStream)

0 commit comments

Comments
 (0)