Pre-defined types
BufReader
BufferIO.BufReader — Type
BufReader{T <: IO} <: AbstractBufReader
BufReader(io::IO, [buffer_size::Int])::BufReaderWrap an IO in a struct with a new buffer, giving it the AbstractBufReader interface.
The BufReader has an infinitely growable buffer, and will only grow the buffer if fill_buffer is called while its internal buffer is full.
This wrapper reads from io using readbytes!. If io is not EOF, and readbytes! reads zero bytes, an exception is thrown when filling the buffer.
Throw an ArgumentError if buffer_size is less than 1.
julia> rdr = BufReader(IOBuffer("Hello, world!\nabc\r\ndef"));
julia> get_buffer(rdr) |> isempty
true
julia> peek(rdr)
0x48
julia> readline(rdr)
"Hello, world!"
julia> String(readavailable(rdr))
"abc\r\ndef"BufWriter
BufferIO.BufWriter — Type
BufWriter{T <: IO} <: AbstractBufWriter
BufWriter(io::IO, [buffer_size::Int])::BufWriterWrap an IO in a struct with a new buffer, giving it the AbstractBufWriter interface.
The BufWriter has an infinitely growable buffer, and will only expand the buffer if grow_buffer is called on it while it does not contain any data (as shown by get_unflushed).
Throw an ArgumentError if buffer_size is < 1.
julia> io = IOBuffer(); wtr = BufWriter(io);
julia> print(wtr, "Hello!")
julia> write(wtr, [0x1234, 0x5678])
4
julia> isempty(read(io)) # wtr not flushed
true
julia> flush(wtr); seekstart(io); String(read(io))
"Hello!4\x12xV"
julia> isempty(get_unflushed(wtr))
trueIOReader
BufferIO.IOReader — Type
IOReader{T <: AbstractBufReader} <: IOWrapper type to convert an AbstractBufReader to an IO.
IOReaders implement the same part of the IO interface as AbstractBufReader, so this type is only used to satisfy type constraints.
Examples
julia> io = CursorReader("hello");
julia> f(x::IO) = String(read(x));
julia> f(io)
ERROR: MethodError: no method matching f(::CursorReader)
[...]
julia> f(IOReader(io))
"hello"IOWriter
BufferIO.IOWriter — Type
IOWriter{T <: AbstractBufWriter} <: IOWrapper type to convert an AbstractBufWriter to an IO.
IOWriters implement the same part of the IO interface as AbstractBufWriter, so this type is only used to satisfy type constraints.
Examples
julia> io = VecWriter();
julia> f(x::IO) = write(x, "hello");
julia> f(io)
ERROR: MethodError: no method matching f(::VecWriter)
[...]
julia> f(IOWriter(io))
5
julia> String(io.vec)
"hello"CursorReader
BufferIO.CursorReader — Type
CursorReader(x) <: AbstractBufReaderA seekable, stateful reader of the content of any object x which implements MemoryView(x)::MemoryView{UInt8}.
Closing it does nothing.
julia> rdr = CursorReader("some\ncontent\nhere");
julia> readline(rdr)
"some"
julia> read(rdr, String)
"content\nhere"
julia> seek(rdr, 8);
julia> read(rdr, String)
"tent\nhere"VecWriter
BufferIO.VecWriter — Type
VecWriter <: AbstractBufWriterA writer backed by a ByteVector. Read the (public) property .vec to get the vector back.
This type is useful as an efficient string builder through takestring!(io).
Functions flush and close do not affect the writer.
Mutating io will mutate vec and vice versa. Neither vec nor io will be invalidated by mutating the other, but doing so may affect the implicit (non-semantic) behaviour (e.g. memory reallocations or efficiency) of the other. For example, repeated and interleaved push!(vec) and write(io, x) may be less efficient, if one operation has memory allocation patterns that is suboptimal for the other operation.
Create with one of the following constructors:
VecWriter([vec::Vector{UInt8}])VecWriter(undef, ::Int)VecWriter(::ByteVector)
Note that, currently, when constructing from a Vector{UInt8}, the vector is invalidated and the VecWriter and its wrapped ByteVector take shared control of the underlying memory. This restriction may be lifted in the future.
A VecWriter has no notion of filesize, and cannot be seeked. Instead, resize the underlying vector io.vec.
julia> vw = VecWriter();
julia> write(vw, "Hello, world!", 0xe1fa)
15
julia> append!(vw.vec, b"More data");
julia> String(vw.vec)
"Hello, world!\xfa\xe1More data"