Skip to content

Commit 8771d7d

Browse files
authored
fix readuntil when stream is empty (#74)
1 parent 23550a6 commit 8771d7d

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/stream.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,10 @@ function Base.readuntil(stream::TranscodingStream, delim::UInt8; keep::Bool=fals
337337
break
338338
end
339339
end
340+
if !@isdefined(ret)
341+
# special case: stream is empty
342+
ret = UInt8[]
343+
end
340344
return ret
341345
end
342346

test/codecnoop.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,11 @@
260260
close(stream)
261261
@test eof(stream) # close
262262

263+
stream = NoopStream(IOBuffer(""))
264+
data = readuntil(stream, 0x00)
265+
@test data isa Vector{UInt8}
266+
@test isempty(data)
267+
263268
@test_throws ArgumentError NoopStream(IOBuffer(), bufsize=0)
264269
@test_throws ArgumentError NoopStream(let s = IOBuffer(); close(s); s; end)
265270
@test_throws ArgumentError TranscodingStream(Noop(), IOBuffer(), bufsize=0)

0 commit comments

Comments
 (0)