Skip to content

Commit a7df41a

Browse files
authored
Fix reading nested streams with stop_on_end=true set. (#191)
1 parent 3be4361 commit a7df41a

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

src/noop.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,18 @@ end
170170
# These methods are overloaded for the `Noop` codec because it has only one
171171
# buffer for efficiency.
172172

173-
function fillbuffer(stream::NoopStream; eager::Bool = false)
173+
function fillbuffer(stream::NoopStream; eager::Bool = false)::Int
174174
changemode!(stream, :read)
175175
buffer = stream.buffer1
176176
@assert buffer === stream.buffer2
177177
if stream.stream isa TranscodingStream && buffer === stream.stream.buffer1
178178
# Delegate the operation when buffers are shared.
179-
return fillbuffer(stream.stream, eager = eager)
179+
underlying_mode::Symbol = stream.stream.state.mode
180+
if underlying_mode === :idle || underlying_mode === :read
181+
return fillbuffer(stream.stream, eager = eager)
182+
else
183+
return 0
184+
end
180185
end
181186
nfilled::Int = 0
182187
while ((!eager && buffersize(buffer) == 0) || (eager && makemargin!(buffer, 0, eager = true) > 0)) && !eof(stream.stream)

src/stream.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -706,10 +706,15 @@ end
706706

707707
# Read as much data as possbile from `input` to the margin of `output`.
708708
# This function will not block if `input` has buffered data.
709-
function readdata!(input::IO, output::Buffer)
709+
function readdata!(input::IO, output::Buffer)::Int
710710
if input isa TranscodingStream && input.buffer1 === output
711711
# Delegate the operation to the underlying stream for shared buffers.
712-
return fillbuffer(input)
712+
mode::Symbol = input.state.mode
713+
if mode === :idle || mode === :read
714+
return fillbuffer(input)
715+
else
716+
return 0
717+
end
713718
end
714719
nread::Int = 0
715720
navail = bytesavailable(input)

test/codecdoubleframe.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,8 @@ DoubleFrameDecoderStream(stream::IO; kwargs...) = TranscodingStream(DoubleFrameD
271271
stop_on_end=true,
272272
)
273273
))
274-
@test_broken read(s1) == b""
275-
@test_broken eof(s1)
274+
@test read(s1) == b""
275+
@test eof(s1)
276276

277277
s2 = NoopStream(
278278
DoubleFrameDecoderStream(
@@ -281,7 +281,7 @@ DoubleFrameDecoderStream(stream::IO; kwargs...) = TranscodingStream(DoubleFrameD
281281
)
282282
)
283283
@test read(s2) == b""
284-
@test_broken eof(s2)
284+
@test eof(s2)
285285
end
286286

287287
test_roundtrip_read(DoubleFrameEncoderStream, DoubleFrameDecoderStream)

0 commit comments

Comments
 (0)