Buffer binary buffer manager

Constructors

  • Parameters

    • buffer: ArrayBuffer
    • Optional byteOffset: number
    • Optional byteLength: number

    Returns Buffer

Methods

  • Allocate a fixed-size byte array memory to the Buffer object.

    Parameters

    • size: number

      Byte Array Size

    Returns void

  • Obtains the buffer object byte array, which can be the original content or a copy. Do not modify the return value directly. Use the slice method to modify the original content.

    Returns any

  • Copy the bytes in the specified range [sourceStart, sourceEnd) of the buffer object to the range [target,] of the target buffer object,

    Ensure that the memory space of the target buffer object is sufficient.

    Parameters

    • dst: Buffer
    • Optional dstStart: number

      Indicates the target start position. The default value is 0.

    • Optional start: number

      Indicates the start position of the source. The default value is 0.

    • Optional end: number

      Source end position. The default value is the size of the source buffer object.

    Returns void

    Example


    import * as buffer from 'buffer';

    let source = buffer.from("1234567890");

    let target = buffer.empty();
    target.alloc(3);
    source.copy(target, 0, 5, 8);

    console.log(target.toString()); // 678
  • Check whether two buffer objects are equal. The comparison principle is to compare the two buffer objects by byte array.

    Parameters

    Returns boolean

  • Obtains the byte value at a specified position of a Buffer object.

    Parameters

    • i: number

      Location index

    Returns any

  • Returns any

    Deprecated

    Use the bytes method.

  • Sets the byte value at the specified position of the buffer object.

    Parameters

    • i: number

      Location index

    • value: any

      Byte Value

    Returns void

  • Obtains the size of the buffer object byte array.

    Returns number

  • From a slice interval [start, end) of the Buffer object, and returns a new Buffer object. Note that the new Buffer object shares the underlying byte array memory with the original Buffer object.

    Parameters

    • Optional start: number

      Start position. The default value is 0.

    • Optional end: number

      End position. The default value is the size of the original buffer.

    Returns Buffer

    Example


    import * as buffer from 'buffer';

    let buf = buffer.from("1234567890");
    let slice = buf.slice(5, 8);

    console.log(buf.toString()); // 1234567890
    console.log(slice.toString()); // 678

    slice.set(1, 65);

    console.log(buf.toString()); // 123456A890
    console.log(slice.toString()); // 6A8
  • Converts the buffer object byte array to a character string.

    Parameters

    • Optional encoding: Encoding

      Character string encoding format. The default value is utf8.

    Returns string