Skip to content

Commit 0d26a46

Browse files
authored
do not close underlying stream when stop_on_end is set (#57)
1 parent 4f1e199 commit 0d26a46

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/stream.jl

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,12 @@ Arguments
7777
The initial buffer size (the default size is 16KiB). The buffer may be
7878
extended whenever `codec` requests so.
7979
- `stop_on_end`:
80-
The flag to stop transcoding on `:end` return code of `codec`. The
81-
transcoded data are readable even after the end of transcoding. Note that
82-
some extra data may be read from `stream` into a buffer and thus `sharedbuf`
83-
must be `true` to reuse `stream`.
80+
The flag to stop transcoding on `:end` return code from `codec`. The
81+
transcoded data are readable even after stopping transcoding process. With
82+
this flag on, `stream` is not closed when the wrapper stream is closed with
83+
`close`. Note that some extra data may be read from `stream` into an
84+
internal buffer, and thus `stream` must be a `TranscodingStream` object and
85+
`sharedbuf` must be `true` to reuse `stream`.
8486
- `sharedbuf`:
8587
The flag to share buffers between adjacent transcoding streams. The value
8688
must be `false` if `stream` is not a `TranscodingStream` object.
@@ -160,10 +162,13 @@ function Base.isopen(stream::TranscodingStream)
160162
end
161163

162164
function Base.close(stream::TranscodingStream)
165+
stopped = stream.state.mode == :stop
163166
if stream.state.mode != :panic
164167
changemode!(stream, :close)
165168
end
166-
close(stream.stream)
169+
if !stopped
170+
close(stream.stream)
171+
end
167172
return nothing
168173
end
169174

0 commit comments

Comments
 (0)