streams.primitives

A collection of compile-time functions to help in identifying stream types and related flavors of them.

Streams come in two main flavors: input and output streams.

Input streams are defined by the presence of a read function with the following signature:

int read(DataType[] buffer)

Output streams are defined by the presence of a write function with the following signature:

int read(DataType[] buffer)

Usually these functions can be used as Template Constraints when defining your own functions and symbols to work with streams.

void useBytes(S)(S stream) if (isInputStream!(S, ubyte)) {
    ubyte[] buffer = new ubyte[8192];
    int bytesRead = stream.read(buffer);
    // Do something with the data.
}

Members

Classes

StreamException
class StreamException

An exception that may be thrown if an illegal operation or error occurs while working with streams. Generally, if an exception is to be thrown while reading or writing in a stream's implementation, a StreamException should be wrapped around it to provide a common interface for error handling.

Functions

asInputRange
auto asInputRange(S stream)

Wraps an existing input stream as a Phobos-style input range, to make any input stream compatible with functions that take input ranges. The given stream is stored as a pointer in the underlying range implementation, so you should still manage ownership of the original stream.

asOutputRange
auto asOutputRange(S stream)

Wraps an existing output stream as a Phobos-style output range with a put method, to make any output stream compatible with functions that take output ranges. The given stream is stored as a pointer in the underlying range implementation, so you should still manage ownership of the original stream.

isByteInputStream
bool isByteInputStream()

Determines if the given stream type is an input stream for ubyte elements.

isByteOutputStream
bool isByteOutputStream()

Determines if the given stream type is an output stream for ubyte elements.

isClosableStream
bool isClosableStream()

Determines if the given template argument is a closable stream type, which defines a void close() method as a means to close and/or deallocate the underlying resource that the stream reads from or writes to.

isFlushableStream
bool isFlushableStream()

Determines if the given template argument is a flushable stream type, which is any output stream that defines a void flush() method, which should cause any data buffered by the stream or its resources to be flushed. The exact nature of how a flush operates is implementation-dependent.

isInputStream
bool isInputStream()

Determines if the given stream type is an input stream for reading data of the given type.

isOutputStream
bool isOutputStream()

Determines if the given stream type is an output stream for writing data of the given type.

isSomeInputStream
bool isSomeInputStream()

Determines if the given template argument is some form of input stream, where an input stream is anything with a read method that takes a single array parameter, and returns an integer number of elements that were read, or -1 in case of error. This method does not care about the type of elements that can be read by the stream.

isSomeOutputStream
bool isSomeOutputStream()

Determines if the given template argument is some form of output stream, where an output stream is anything with a write method that takes a single array parameter, and returns an integer number of elements that were read, or -1 in case of error. This method does not care about the type of elements that can be read by the stream.

isSomeStream
bool isSomeStream()

Determines if the given template argument is a stream of any kind; that is, it is at least implementing the functions required to be an input or output stream.

isSomeStream
bool isSomeStream()

Determines if the given stream type is an input or output stream for data of the given type.

Meta