Array.slice

Access buffer content.

  1. void[] slice()
  2. void[] slice(size_t size, bool eat)
    class Array
    final
    void[]
    slice
    (
    size_t size
    ,
    bool eat = true
    )

Parameters

size size_t

Number of bytes to access.

eat bool

Whether to consume the content or not.

Return Value

Type: void[]

The corresponding buffer slice when successful, or null if there's not enough data available (Eof; Eob).

Remarks: Slices readable data. The specified number of bytes is readd from the buffer, and marked as having been read when the 'eat' parameter is set true. When 'eat' is set false, the read position is not adjusted.

Note that the slice cannot be larger than the size of the buffer ~ use method read(void[]) instead where you simply want the content copied.

Note also that the slice should be .dup'd if you wish to retain it.

Examples

// create a buffer with some content
auto buffer = new Buffer ("hello world");

// consume everything unread
auto slice = buffer.slice (buffer.readable);

Meta