Skip to content

Commit

Permalink
fix skip
Browse files Browse the repository at this point in the history
  • Loading branch information
bicycle1885 committed Jun 11, 2017
1 parent 10788ca commit 37d9347
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/stream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function Base.skip(stream::TranscodingStream, offset::Integer)
buffer1 = stream.state.buffer1
skipped = 0
if state == :read
while buffersize(buffer1) < offset - skipped && !eof(stream)
while !eof(stream) && buffersize(buffer1) < offset - skipped
n = buffersize(buffer1)
emptybuffer!(buffer1)
skipped += n
Expand Down
17 changes: 17 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,21 @@ using Base.Test
@test read(stream, UInt8) == data[3]
skip(stream, 5)
@test read(stream, UInt8) == data[9]
skip(stream, 7)
@test eof(stream)
close(stream)

# skip offset > bufsize
data = collect(0x00:0x0f)
stream = TranscodingStream(Identity(), IOBuffer(data), bufsize=2)
@test read(stream, UInt8) == data[1]
skip(stream, 4)
@test read(stream, UInt8) == data[6]
skip(stream, 3)
@test read(stream, UInt8) == data[10]
skip(stream, 6)
@test eof(stream)
close(stream)

s = TranscodingStream(Identity(), IOBuffer(b"baz"))
@test endof(s.state.buffer1) == 0
Expand Down Expand Up @@ -94,6 +109,8 @@ using Base.Test
TranscodingStreams.test_roundtrip_read(IdentityStream, IdentityStream)
TranscodingStreams.test_roundtrip_write(IdentityStream, IdentityStream)
TranscodingStreams.test_roundtrip_lines(IdentityStream, IdentityStream)

@test_throws ArgumentError TranscodingStream(Identity(), IOBuffer(), bufsize=0)
end

for pkg in ["CodecZlib", "CodecBzip2", "CodecXz", "CodecZstd"]
Expand Down

0 comments on commit 37d9347

Please sign in to comment.