Skip to content

Commit

Permalink
error if seekstart in write mode
Browse files Browse the repository at this point in the history
  • Loading branch information
nhz2 committed Oct 17, 2023
1 parent 00f2fdb commit c1395b9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/stream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,10 @@ end
# ---------------

function Base.seekstart(stream::TranscodingStream)
checkmode(stream)
mode = stream.state.mode
@checkmode (:idle, :read, :write)
if mode == :read || mode == :write
@checkmode (:idle, :read)
if mode == :read
callstartproc(stream, mode)
emptybuffer!(stream.state.buffer1)
emptybuffer!(stream.state.buffer2)
Expand Down
8 changes: 2 additions & 6 deletions test/codecquadruple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,10 @@ end
stream = TranscodingStream(QuadrupleCodec(), sink, bufsize=16)
write(stream, "x")
# seekstart must not delete user data even if it errors.
try
seekstart(stream)
catch e
e isa ArgumentError || rethrow()
end
@test_throws ArgumentError seekstart(stream)
write(stream, TranscodingStreams.TOKEN_END)
flush(stream)
@test_broken take!(sink) == b"xxxx"
@test take!(sink) == b"xxxx"
close(stream)
end
end

0 comments on commit c1395b9

Please sign in to comment.