Skip to content

Commit 7df0c44

Browse files
authored
implement Base.readavailable (#12)
1 parent f15a73b commit 7df0c44

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/stream.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,13 @@ function Base.nb_available(stream::TranscodingStream)
237237
return buffersize(stream.state.buffer1)
238238
end
239239

240+
function Base.readavailable(stream::TranscodingStream)
241+
n = nb_available(stream)
242+
data = Vector{UInt8}(n)
243+
unsafe_read(stream, pointer(data), n)
244+
return data
245+
end
246+
240247

241248
# Write Functions
242249
# ---------------

test/runtests.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,14 @@ end
172172
end
173173

174174
@testset "Noop Codec" begin
175+
stream = NoopStream(IOBuffer("foobar"))
176+
@test nb_available(stream) === 0
177+
@test readavailable(stream) == b""
178+
@test read(stream, UInt8) === UInt8('f')
179+
@test nb_available(stream) === 5
180+
@test readavailable(stream) == b"oobar"
181+
close(stream)
182+
175183
data = b"foo"
176184
@test transcode(Noop(), data) !== data
177185
TranscodingStreams.test_roundtrip_transcode(Noop, Noop)

0 commit comments

Comments
 (0)