Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Unreleased

# 0.3.0
## Breaking changes
* When a `LineViewIterator` is iterated, and the underlying IO cannot buffer an entire line, an `IOError` with kind `BufferTooShort` is now thrown, whereas previously, an `ArgumentError` was thrown.

# 0.2.3
* Add function `relative_seek`
* Add `write_repeated`
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "BufferIO"
uuid = "ff366017-094f-4144-bd70-a828a0d67152"
version = "0.2.3"
version = "0.3.0"
authors = ["Jakob Nybo Nissen <jakobnybonissen@gmail.com>"]

[deps]
Expand Down
7 changes: 4 additions & 3 deletions src/lineiterator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,16 @@ or the remainder of the data in `io` if no `\\n` byte was found.
If the input is empty, this iterator is also empty.

If `x` had a limited buffer size, and cannot grow its buffer,
and an entire line cannot be kept in the buffer, an `ArgumentError` is thrown.
and an entire line cannot be kept in the buffer, an `IOError` is thrown,
with its kind being `IOErrorKinds.BufferTooShort`.

The resulting iterator will NOT close `x` when exhausted, this must be handled elsewhere.

### Iterator state and io advancement
The resulting iterator `itr::LineViewIterator`'s state is guaranteed, public interface:

* `iterate(itr)` is equivalent to `iterate(itr, 0)`
* `iterate(itr, n::Int)` is equivalent to `consume(x, n); iterate(itr)`
* `iterate(itr, n::Int)` is equivalent to `consume(itr.reader, n); iterate(itr)`
* The state returned by `iterate` is an `Int` equal to the length of the line
emitted, plus the number of stripped `\\r\\n` or `\\n` bytes, if `chomp`.

Expand Down Expand Up @@ -91,7 +92,7 @@ function Base.iterate(x::LineViewIterator, state::Int = 0)

pos = buffer_until(x.reader, 0x0a)
if pos isa HitBufferLimit
throw(ArgumentError("Buffer too short to buffer a whole line, and cannot be expanded."))
throw(IOError(IOErrorKinds.BufferTooShort))
elseif pos === nothing
# No more newlines until EOF. Close as we reached EOF
buffer = get_buffer(x.reader)
Expand Down
Loading