From 37d9347ad938fd4e3fe57dcee24adc1ad36d73d4 Mon Sep 17 00:00:00 2001 From: Kenta Sato Date: Sun, 11 Jun 2017 10:38:14 +0900 Subject: [PATCH] fix skip --- src/stream.jl | 2 +- test/runtests.jl | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/stream.jl b/src/stream.jl index 4910e7b9..739ba78e 100644 --- a/src/stream.jl +++ b/src/stream.jl @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index 66c8ca76..0ca29194 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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 @@ -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"]