Skip to content

Commit

Permalink
Base.seek and Base.skip should return stream (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
nhz2 committed Oct 16, 2023
1 parent 337f418 commit 1cb583d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/noop.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,19 @@ end
function Base.seek(stream::NoopStream, pos::Integer)
seek(stream.stream, pos)
initbuffer!(stream.state.buffer1)
return
return stream
end

function Base.seekstart(stream::NoopStream)
seekstart(stream.stream)
initbuffer!(stream.state.buffer1)
return
return stream
end

function Base.seekend(stream::NoopStream)
seekend(stream.stream)
initbuffer!(stream.state.buffer1)
return
return stream
end

function Base.unsafe_read(stream::NoopStream, output::Ptr{UInt8}, nbytes::UInt)
Expand Down
2 changes: 1 addition & 1 deletion src/stream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ function Base.skip(stream::TranscodingStream, offset::Integer)
# TODO: support skip in write mode
throw(ArgumentError("not in read mode"))
end
return
return stream
end

"""
Expand Down
8 changes: 4 additions & 4 deletions test/codecnoop.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@
close(stream)

stream = TranscodingStream(Noop(), IOBuffer(b"foobarbaz"))
seek(stream, 2)
@test stream == seek(stream, 2)
@test read(stream, 3) == b"oba"
seek(stream, 0)
@test read(stream, 3) == b"foo"
seekstart(stream)
@test stream == seekstart(stream)
@test read(stream, 3) == b"foo"
seekend(stream)
@test stream == seekend(stream)
@test eof(stream)
close(stream)

Expand All @@ -97,7 +97,7 @@
data = collect(0x00:0x0f)
stream = TranscodingStream(Noop(), IOBuffer(data), bufsize=2)
@test read(stream, UInt8) == data[1]
skip(stream, 4)
@test stream == skip(stream, 4)
@test read(stream, UInt8) == data[6]
skip(stream, 3)
@test read(stream, UInt8) == data[10]
Expand Down

0 comments on commit 1cb583d

Please sign in to comment.