(Note that upstream is closer to the source, and downstream is
further away.)
- alias flush clear ¶
-
Clear/flush are the same.
- alias InputFilter.input input ¶
-
- invariant ¶
-
Ensure the buffer remains valid between method calls.
- this(InputStream stream) ¶
-
stream | An input stream. |
capacity | Desired buffer capacity. |
Construct a Buffer upon the provided input stream.
- this(InputStream stream, size_t capacity) ¶
-
stream | An input stream. |
capacity | Desired buffer capacity. |
Construct a Buffer upon the provided input stream.
- InputBuffer create(InputStream stream) [static] ¶
-
Attempt to share an upstream Buffer, and create an instance
where there's not one available.
If an upstream Buffer instances is visible, it will be shared.
Otherwise, a new instance is created based upon the bufferSize
exposed by the stream endpoint (conduit).
- size_t populate() [final] ¶
-
Place more data from the source stream into this buffer, and
return the number of bytes added. This does not compress the
current buffer content, so consider doing that explicitly.
Number of bytes added, which will be Eof when there
is no further input available. Zero is also a valid
response, meaning no data was actually added.
- void[] opSlice(size_t start, size_t end) [final] ¶
-
Return a void[] slice of the buffer from start to end, where
end is exclusive.
- void[] slice() [final] ¶
-
Retrieve the valid content.
A void[] slice of the buffer.
Return a void[] slice of the buffer, from the current position
up to the limit of valid content. The content remains in the
buffer for future extraction.
- void[] slice(size_t size, bool eat = true) [final] ¶
-
size | Number of bytes to access. |
eat | Whether to consume the content or not. |
The corresponding buffer slice when successful, or
null if there's not enough data available (Eof; Eob).
Read a slice of data from the buffer, loading from the
conduit as necessary. The specified number of bytes is
sliced from the buffer, and marked as having been read
when the 'eat' parameter is set true. When 'eat' is set
false, the read position is not adjusted.
Note that the slice cannot be larger than the size of
the buffer ~ use method fill(void[]) instead where you
simply want the content copied, or use conduit.read()
to extract directly from an attached conduit. Also note
that if you need to retain the slice, then it should be
.dup'd before the buffer is compressed or repopulated.
1
2
3
4
5
|
// create a buffer with some content
auto buffer = new Buffer ("hello world");
// consume everything unread
auto slice = buffer.slice (buffer.readable);
|
- size_t reader(scope size_t delegate(const(void)[]) dg) [final] ¶
-
Read directly from this buffer.
dg | Callback to provide buffer access to. |
Returns whatever the delegate returns.
Exposes the raw data buffer at the current _read position. The
delegate is provided with a void[] representing the available
data, and should return zero to leave the current _read position
intact.
If the delegate consumes data, it should return the number of
bytes consumed; or IConduit.Eof to indicate an error.
- size_t writer(scope size_t delegate(void[]) dg) [public] ¶
-
dg | The callback to provide buffer access to. |
Returns whatever the delegate returns.
Exposes the raw data buffer at the current _write position,
The delegate is provided with a void[] representing space
available within the buffer at the current _write position.
The delegate should return the appropriate number of bytes
if it writes valid content, or IConduit.Eof on error.
- size_t read(void[] dst) [override, final] ¶
-
Transfer content into the provided dst.
dst | Destination of the content. |
Return the number of bytes read, which may be less than
dst.length. Eof is returned when no further content is
available.
Populates the provided array with content. We try to
satisfy the request from the buffer content, and read
directly from an attached conduit when the buffer is
empty.
- size_t fill(void[] dst, bool exact = false) [final] ¶
-
Fill the provided buffer. Returns the number of bytes
actually read, which will be less that dst.length when
Eof has been reached and Eof thereafter.
dst | Where data should be placed. |
exact | Whether to throw an exception when dst is not
filled (an Eof occurs first). Defaults to false. |
- bool skip(ptrdiff_t size) [final] ¶
-
Move the current read location.
size | The number of bytes to move. |
Returns true if successful, false otherwise.
Skip ahead by the specified number of bytes, streaming from
the associated conduit as necessary.
Can also reverse the read position by 'size' bytes, when size
is negative. This may be used to support lookahead operations.
Note that a negative size will fail where there is not sufficient
content available in the buffer (can't _skip beyond the beginning).
- long seek(long offset, Anchor start = Begin) [override, final] ¶
-
Move the current read location.
- bool next(scope size_t delegate(const(void)[]) scan) [final] ¶
-
scan | The delegate to invoke with the current content. |
Returns true if a token was isolated, false otherwise.
Upon success, the delegate should return the byte-based
index of the consumed pattern (tail end of it). Failure
to match a pattern should be indicated by returning an
Eof
Each pattern is expected to be stripped of the delimiter.
An end-of-file condition causes trailing content to be
placed into the token. Requests made beyond Eof result
in empty matches (length is zero).
Note that additional iterator and/or reader instances
will operate in lockstep when bound to a common buffer.
- size_t reserve(size_t space) [final] ¶
-
Reserve the specified space within the buffer, compressing
existing content as necessary to make room.
Returns the current read point, after compression if that
was required.
- BufferedInput compress() [@property, final] ¶
-
The buffer instance.
If we have some data left after an export, move it to
front-of-buffer and set position to be just after the
remains. This is for supporting certain conduits which
choose to write just the initial portion of a request.
Limit is set to the amount of data remaining. Position
is always reset to zero.
- size_t drain(OutputStream dst) [final] ¶
-
Drain buffer content to the specific conduit.
Returns the number of bytes written, or Eof.
Write as much of the buffer that the associated conduit
can consume. The conduit is not obliged to consume all
content, so some may remain within the buffer.
- size_t limit() [@property, final, const] ¶
-
Returns the limit of readable content within this buffer.
Each buffer has a capacity, a limit, and a position. The
capacity is the maximum content a buffer can contain, limit
represents the extent of valid content, and position marks
the current read location.
- size_t capacity() [final, const] ¶
-
Returns the maximum capacity of this buffer.
Each buffer has a capacity, a limit, and a position. The
capacity is the maximum content a buffer can contain, limit
represents the extent of valid content, and position marks
the current read location.
- size_t position() [@property, final, const] ¶
-
Access buffer read position.
Returns the current read-position within this buffer.
Each buffer has a capacity, a limit, and a position. The
capacity is the maximum content a buffer can contain, limit
represents the extent of valid content, and position marks
the current read location.
- size_t readable() [@property, final, const] ¶
-
Return count of _readable bytes remaining in buffer. This is
calculated simply as limit() - position().
- inout(T)[] convert(T)(inout(void)[] x) [static] ¶
-
Cast to a target type without invoking the wrath of the
runtime checks for misalignment. Instead, we truncate the
array length.
- BufferedInput flush() [override, final] ¶
-
Reset 'position' and 'limit' to zero. This effectively
clears all content from the buffer.
- void input(InputStream source) [@property, final] ¶
-
- void[] load(size_t max = max) [override, final] ¶
-
Load the bits from a stream, up to an indicated length, and
return them all in an array. The function may consume more
than the indicated size where additional data is available
during a block read operation, but will not wait for more
than specified. An Eof terminates the operation.
Returns an array representing the content, and throws
IOException on error.