readUntil

Reads all data of a stream until the specified end marker is detected.

  1. ubyte[] readUntil(InputStream stream, ubyte[] end_marker, size_t max_bytes, IAllocator alloc)
  2. void readUntil(InputStream stream, OutputStream dst, ubyte[] end_marker, ulong max_bytes)
  3. void readUntil(InputStream stream, R dst, ubyte[] end_marker, ulong max_bytes)
    void
    readUntil
    (
    R
    InputStream
    )
    (
    InputStream stream
    ,
    ref R dst
    ,
    in ubyte[] end_marker
    ,
    ulong max_bytes = ulong.max
    )
    if (
    isOutputRange!(R, ubyte) &&
    isInputStream!InputStream
    )

Parameters

stream InputStream

The input stream which is searched for end_marker

end_marker ubyte[]

The byte sequence which is searched in the stream

max_bytes ulong

An optional limit of how much data is to be read from the input stream; if the limit is reaached before hitting the end marker, an exception is thrown.

dst R

The output stream, to which the prefix to the end marker of the input stream is written

Return Value

Type: void

The string variant of this function returns the complete prefix to the end marker of the input stream, excluding the end marker itself.

Throws

An exception if either the stream end was hit without hitting a marker first, or if more than max_bytes have been read from the stream in case of max_bytes != 0.

Remarks: This function uses an algorithm inspired by the Boyer-Moore string search algorithm. However, contrary to the original algorithm, it will scan the whole input string exactly once, without jumping over portions of it. This allows the algorithm to work with constant memory requirements and without the memory copies that would be necessary for streams that do not hold their complete data in memory.

The current implementation has a run time complexity of O(n*m+m²) and O(n+m) in typical cases, with n being the length of the scanned input string and m the length of the marker.

Meta