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)
    ubyte[]
    readUntil
    (
    InputStream
    )
    (
    InputStream stream
    ,
    in ubyte[] end_marker
    ,
    size_t max_bytes = size_t.max
    ,
    IAllocator alloc = vibeThreadAllocator()
    )
    if (
    isInputStream!InputStream
    )
  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)

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 size_t

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.

alloc IAllocator

An optional allocator that is used to build the result string in the string variant of this function

Return Value

Type: ubyte[]

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