Struct BufferedOutputRange

A buffering output range that writes to another output range in batches.

struct BufferedOutputRange(ORangeT, ElemT)
  
if (isBlockOutputRange!(ORangeT, ElemT));

Sometimes there are efficiency costs associated with writing a single element at a time. Some OutputRanges take care of this themselves, and others do not. This is a utility that generalizes this buffering logic when it is needed.

For example, suppose a FileOutputRange has element type ubyte[] (it writes many bytes at a time). A BufferedOutputRange wraps another OutputRange, like the FileOutputRange, and permits put calls of ubyte or ubyte[] and stores them in a memory buffer. When this buffer is full, a single put(ubyte[]) call will be made with the buffer's contents to the provided FileOutputRange.

The standard OutputRange interface is expanded with flush(), which causes the current memory buffer's contents to be written immediately to the wrapped OutputRange.

Constructors

NameDescription
this (oRange, bufSize) Constructs a BufferedOutputRange which writes to oRange in batches up to bufSize.

Methods

NameDescription
flush () Writes any buffered elements into the underlying output range.
put (elems) Adds many elements, which may trigger flushes to the output range.
put (elem) Adds a single element which may be buffered or trigger a flush to the output range.

Parameters

NameDescription
ORangeT The type of the wrapped OutputRange, capable of writing batches of elements.
ElemT The type of items in the batch that can be written to ORangeT.