Options
All
  • Public
  • Public/Protected
  • All
Menu

A Buffer is a variable-sized buffer of bytes with read() and write() methods. Based on https://golang.org/pkg/bytes/#Buffer

Hierarchy

  • Buffer

Implements

Index

Constructors

constructor

  • new Buffer(ab?: ArrayBuffer): Buffer
  • Parameters

    • Optional ab: ArrayBuffer

    Returns Buffer

Properties

capacity

capacity: number

Returns the capacity of the buffer's underlying byte slice, that is, the total space allocated for the buffer's data.

length

length: number

length is a getter that returns the number of bytes of the unread portion of the buffer

Methods

bytes

  • bytes(): Uint8Array
  • bytes() returns a slice holding the unread portion of the buffer. The slice is valid for use only until the next buffer modification (that is, only until the next call to a method like read(), write(), reset(), or truncate()). The slice aliases the buffer content at least until the next buffer modification, so immediate changes to the slice will affect the result of future reads.

    Returns Uint8Array

empty

  • empty(): boolean
  • empty() returns whether the unread portion of the buffer is empty.

    Returns boolean

grow

  • grow(n: number): void
  • grow() grows the buffer's capacity, if necessary, to guarantee space for another n bytes. After grow(n), at least n bytes can be written to the buffer without another allocation. If n is negative, grow() will panic. If the buffer can't grow it will throw ErrTooLarge. Based on https://golang.org/pkg/bytes/#Buffer.Grow

    Parameters

    • n: number

    Returns void

read

  • Parameters

    • p: Uint8Array

    Returns Promise<ReadResult>

readFrom

  • readFrom(r: Reader): Promise<number>
  • readFrom() reads data from r until EOF and appends it to the buffer, growing the buffer as needed. It returns the number of bytes read. If the buffer becomes too large, readFrom will panic with ErrTooLarge. Based on https://golang.org/pkg/bytes/#Buffer.ReadFrom

    Parameters

    Returns Promise<number>

readFromSync

  • Sync version of readFrom

    Parameters

    Returns number

readSync

  • readSync() reads the next len(p) bytes from the buffer or until the buffer is drained. The return value n is the number of bytes read. If the buffer has no data to return, eof in the response will be true.

    Parameters

    • p: Uint8Array

    Returns ReadResult

reset

  • reset(): void
  • reset() resets the buffer to be empty, but it retains the underlying storage for use by future writes. reset() is the same as truncate(0)

    Returns void

toString

  • toString(): string
  • toString() returns the contents of the unread portion of the buffer as a string. Warning - if multibyte characters are present when data is flowing through the buffer, this method may result in incorrect strings due to a character being split.

    Returns string

truncate

  • truncate(n: number): void
  • truncate() discards all but the first n unread bytes from the buffer but continues to use the same allocated storage. It throws if n is negative or greater than the length of the buffer.

    Parameters

    • n: number

    Returns void

write

  • write(p: Uint8Array): Promise<number>
  • Parameters

    • p: Uint8Array

    Returns Promise<number>

writeSync

  • writeSync(p: Uint8Array): number
  • Parameters

    • p: Uint8Array

    Returns number

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc