Range that reads up to a fixed size chunk of data from a stream at a time.
Initializes the range. A byte buffer with the given size is allocated to hold the chunks.
Stream source | A stream that can be read from. |
size_t size | The size of each chunk to read at a time. |
Initializes the range with the specified buffer. This is useful for providing your own buffer that may be stack allocated.
Stream source | A stream that can be read from. |
ubyte[] buffer | A byte array to hold each chunk as it is read. |
Reads the next chunk from the stream.
Returns true if there are no more chunks to be read from the stream.
Convenience function for creating a ByChunk range over a stream.
import std.digest.digest : digest; import std.digest.sha : SHA1; import io.file; // Hash a file, 4KiB chunks at a time ubyte[4096] buf; auto sha1 = digest!SHA1(File("foo").byChunk(buf));
Wraps a stream in a range interface such that blocks of a fixed size are read from the source. It is assumed that the stream is buffered so that performance is not adversely affected.
Since streams and ranges are fundamentally different, this is useful for performing range operations on streams.
Initializes the range with a source stream.
Removes one block from the stream.
The range is considered empty when less than T.sizeof bytes can be read from the stream.
Helper function for constructing a block range.
import std.algorithm : equal; import std.range : take;
Checks if the given region ends with the given separator.
Checks if the given function can be used with Splitter.
static assert(isSplitFunction!(endsWithSeparator, char, char)); static assert(isSplitFunction!(endsWithSeparator, char, string));
Splits a stream using a separator. The separator can be a single element or a bidirectional range of elements.
Convenience function for returning a stream splitter.
T | Type of each element in the stream. |
Stream stream | A sink stream that can be read from. |
Separator separator | An element or range of elements to split on. |
// Get a list of words from standard input. import io; import std.algorithm : map, filter; import std.array : array; auto words = stdin.splitter!char(' ') .filter!(w => w != "") .map!(w => w.idup) .array;