Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Buffer

Hierarchy

  • Uint8Array
    • Buffer

Indexable

[index: number]: number

Index

Constructors

constructor

  • new Buffer(str: string, encoding?: string): Buffer
  • new Buffer(size: number): Buffer
  • new Buffer(array: Uint8Array): Buffer
  • new Buffer(arrayBuffer: ArrayBuffer): Buffer
  • new Buffer(array: any[]): Buffer
  • new Buffer(buffer: Buffer): Buffer

Properties

Static BYTES_PER_ELEMENT

BYTES_PER_ELEMENT: number

The size in bytes of each element in the array.

Static Uint8Array

Uint8Array: Uint8ArrayConstructor

Static buffer

buffer: ArrayBuffer

The ArrayBuffer instance referenced by the array.

Static byteOffset

byteOffset: number

The offset in bytes of the array.

Static length

length: number

The length of the array.

Methods

compare

copy

  • copy(targetBuffer: Buffer, targetStart?: number, sourceStart?: number, sourceEnd?: number): number

entries

equals

  • equals(otherBuffer: Buffer): boolean

fill

  • fill(value: any, offset?: number, end?: number)

includes

  • includes(value: string | number | Buffer, byteOffset?: number, encoding?: string): boolean

indexOf

  • indexOf(value: string | number | Buffer, byteOffset?: number, encoding?: string): number

keys

lastIndexOf

  • lastIndexOf(value: string | number | Buffer, byteOffset?: number, encoding?: string): number

readDoubleBE

  • readDoubleBE(offset: number, noAssert?: boolean): number

readDoubleLE

  • readDoubleLE(offset: number, noAssert?: boolean): number

readFloatBE

  • readFloatBE(offset: number, noAssert?: boolean): number

readFloatLE

  • readFloatLE(offset: number, noAssert?: boolean): number

readInt16BE

  • readInt16BE(offset: number, noAssert?: boolean): number

readInt16LE

  • readInt16LE(offset: number, noAssert?: boolean): number

readInt32BE

  • readInt32BE(offset: number, noAssert?: boolean): number

readInt32LE

  • readInt32LE(offset: number, noAssert?: boolean): number

readInt8

  • readInt8(offset: number, noAssert?: boolean): number

readIntBE

  • readIntBE(offset: number, byteLength: number, noAssert?: boolean): number

readIntLE

  • readIntLE(offset: number, byteLength: number, noAssert?: boolean): number

readUInt16BE

  • readUInt16BE(offset: number, noAssert?: boolean): number

readUInt16LE

  • readUInt16LE(offset: number, noAssert?: boolean): number

readUInt32BE

  • readUInt32BE(offset: number, noAssert?: boolean): number

readUInt32LE

  • readUInt32LE(offset: number, noAssert?: boolean): number

readUInt8

  • readUInt8(offset: number, noAssert?: boolean): number

readUIntBE

  • readUIntBE(offset: number, byteLength: number, noAssert?: boolean): number

readUIntLE

  • readUIntLE(offset: number, byteLength: number, noAssert?: boolean): number

slice

  • slice(start?: number, end?: number): Buffer

swap16

  • swap16()

swap32

  • swap32()

swap64

  • swap64()

toJSON

  • toJSON(): any

toString

  • toString(encoding?: string, start?: number, end?: number): string

values

write

  • write(string: string, offset?: number, length?: number, encoding?: string): number

writeDoubleBE

  • writeDoubleBE(value: number, offset: number, noAssert?: boolean): number

writeDoubleLE

  • writeDoubleLE(value: number, offset: number, noAssert?: boolean): number

writeFloatBE

  • writeFloatBE(value: number, offset: number, noAssert?: boolean): number

writeFloatLE

  • writeFloatLE(value: number, offset: number, noAssert?: boolean): number

writeInt16BE

  • writeInt16BE(value: number, offset: number, noAssert?: boolean): number

writeInt16LE

  • writeInt16LE(value: number, offset: number, noAssert?: boolean): number

writeInt32BE

  • writeInt32BE(value: number, offset: number, noAssert?: boolean): number

writeInt32LE

  • writeInt32LE(value: number, offset: number, noAssert?: boolean): number

writeInt8

  • writeInt8(value: number, offset: number, noAssert?: boolean): number

writeIntBE

  • writeIntBE(value: number, offset: number, byteLength: number, noAssert?: boolean): number

writeIntLE

  • writeIntLE(value: number, offset: number, byteLength: number, noAssert?: boolean): number

writeUInt16BE

  • writeUInt16BE(value: number, offset: number, noAssert?: boolean): number

writeUInt16LE

  • writeUInt16LE(value: number, offset: number, noAssert?: boolean): number

writeUInt32BE

  • writeUInt32BE(value: number, offset: number, noAssert?: boolean): number

writeUInt32LE

  • writeUInt32LE(value: number, offset: number, noAssert?: boolean): number

writeUInt8

  • writeUInt8(value: number, offset: number, noAssert?: boolean): number

writeUIntBE

  • writeUIntBE(value: number, offset: number, byteLength: number, noAssert?: boolean): number

writeUIntLE

  • writeUIntLE(value: number, offset: number, byteLength: number, noAssert?: boolean): number

Static alloc

  • alloc(size: number, fill?: string | Buffer | number, encoding?: string): Buffer
  • Allocates a new Buffer of size bytes. If fill is undefined, the Buffer will be zero-filled.

    Parameters

    • size: number

      The desired length of the new Buffer

    • Optional fill: string | Buffer | number

      A value to pre-fill the new Buffer with. Default: 0

    • Optional encoding: string

      If fill is a string, this is its encoding. Default: 'utf8'

    Returns Buffer

Static allocUnsafe

  • allocUnsafe(size: number): Buffer
  • Allocates a new non-zero-filled Buffer of size bytes. The size must be less than or equal to the value of buffer.kMaxLength. Otherwise, a RangeError is thrown. A zero-length Buffer will be created if size <= 0.

    The underlying memory for Buffer instances created in this way is not initialized. The contents of the newly created Buffer are unknown and may contain sensitive data. Use buf.fill(0) to initialize such Buffer instances to zeroes.

    Parameters

    • size: number

      The desired length of the new Buffer

    Returns Buffer

Static byteLength

  • byteLength(string: string, encoding?: string): number
  • Gives the actual byte length of a string. encoding defaults to 'utf8'. This is not the same as String.prototype.length since that returns the number of characters in a string.

    Parameters

    • string: string

      string to test.

    • Optional encoding: string

      encoding used to evaluate (defaults to 'utf8')

    Returns number

Static concat

  • Returns a buffer which is the result of concatenating all the buffers in the list together.

    If the list has no items, or if the totalLength is 0, then it returns a zero-length buffer. If the list has exactly one item, then the first item of the list is returned. If the list has more than one item, then a new Buffer is created.

    Parameters

    • list: Buffer[]

      An array of Buffer objects to concatenate

    • Optional totalLength: number

      Total length of the buffers when concatenated. If totalLength is not provided, it is read from the buffers in the list. However, this adds an additional loop to the function, so it is faster to provide the length explicitly.

    Returns Buffer

Static copyWithin

  • copyWithin(target: number, start: number, end?: number)
  • Returns the this object after copying a section of the array identified by start and end to the same array starting at position target

    Parameters

    • target: number

      If target is negative, it is treated as length+target where length is the length of the array.

    • start: number

      If start is negative, it is treated as length+start. If end is negative, it is treated as length+end.

    • Optional end: number

      If not specified, length of the this object is used as its default value.

Static every

  • every(callbackfn: function, thisArg?: any): boolean
  • Determines whether all the members of an array satisfy the specified test.

    Parameters

    • callbackfn: function

      A function that accepts up to three arguments. The every method calls the callbackfn function for each element in array1 until the callbackfn returns false, or until the end of the array.

        • (value: number, index: number, array: Uint8Array): boolean
        • Parameters

          • value: number
          • index: number
          • array: Uint8Array

          Returns boolean

    • Optional thisArg: any

      An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.

    Returns boolean

Static fill

  • fill(value: number, start?: number, end?: number)
  • Returns the this object after filling the section identified by start and end with value

    Parameters

    • value: number

      value to fill array section with

    • Optional start: number

      index to start filling the array at. If start is negative, it is treated as length+start where length is the length of the array.

    • Optional end: number

      index to stop filling the array at. If end is negative, it is treated as length+end.

Static filter

  • filter(callbackfn: function, thisArg?: any): Uint8Array
  • Returns the elements of an array that meet the condition specified in a callback function.

    Parameters

    • callbackfn: function

      A function that accepts up to three arguments. The filter method calls the callbackfn function one time for each element in the array.

        • (value: number, index: number, array: Uint8Array): any
        • Parameters

          • value: number
          • index: number
          • array: Uint8Array

          Returns any

    • Optional thisArg: any

      An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.

    Returns Uint8Array

Static find

  • find(predicate: function, thisArg?: any): number | undefined
  • Returns the value of the first element in the array where predicate is true, and undefined otherwise.

    Parameters

    • predicate: function

      find calls predicate once for each element of the array, in ascending order, until it finds one where predicate returns true. If such an element is found, find immediately returns that element value. Otherwise, find returns undefined.

        • (value: number, index: number, obj: Array<number>): boolean
        • Parameters

          • value: number
          • index: number
          • obj: Array<number>

          Returns boolean

    • Optional thisArg: any

      If provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined is used instead.

    Returns number | undefined

Static findIndex

  • findIndex(predicate: function, thisArg?: any): number
  • Returns the index of the first element in the array where predicate is true, and undefined otherwise.

    Parameters

    • predicate: function

      find calls predicate once for each element of the array, in ascending order, until it finds one where predicate returns true. If such an element is found, findIndex immediately returns that element index. Otherwise, findIndex returns -1.

        • (value: number): boolean
        • Parameters

          • value: number

          Returns boolean

    • Optional thisArg: any

      If provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined is used instead.

    Returns number

Static forEach

  • forEach(callbackfn: function, thisArg?: any): void
  • Performs the specified action for each element in an array.

    Parameters

    • callbackfn: function

      A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array.

        • (value: number, index: number, array: Uint8Array): void
        • Parameters

          • value: number
          • index: number
          • array: Uint8Array

          Returns void

    • Optional thisArg: any

      An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.

    Returns void

Static from

  • from(array: any[]): Buffer
  • from(arrayBuffer: ArrayBuffer, byteOffset?: number, length?: number): Buffer
  • from(buffer: Buffer): Buffer
  • from(str: string, encoding?: string): Buffer
  • Allocates a new Buffer using an {array} of octets.

    Parameters

    • array: any[]

    Returns Buffer

  • When passed a reference to the .buffer property of a TypedArray instance, the newly created Buffer will share the same allocated memory as the TypedArray. The optional {byteOffset} and {length} arguments specify a memory range within the {arrayBuffer} that will be shared by the Buffer.

    Parameters

    • arrayBuffer: ArrayBuffer

      The .buffer property of a TypedArray or a new ArrayBuffer()

    • Optional byteOffset: number
    • Optional length: number

    Returns Buffer

  • Copies the passed {buffer} data onto a new Buffer instance.

    Parameters

    Returns Buffer

  • Creates a new Buffer containing the given JavaScript string {str}. If provided, the {encoding} parameter identifies the character encoding. If not provided, {encoding} defaults to 'utf8'.

    Parameters

    • str: string
    • Optional encoding: string

    Returns Buffer

Static indexOf

  • indexOf(searchElement: number, fromIndex?: number): number
  • Returns the index of the first occurrence of a value in an array.

    Parameters

    • searchElement: number

      The value to locate in the array.

    • Optional fromIndex: number

      The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0.

    Returns number

Static isBuffer

  • isBuffer(obj: any): boolean

Static isEncoding

  • isEncoding(encoding: string): boolean
  • Returns true if encoding contains a supported character encoding, or false otherwise.

    Parameters

    • encoding: string

      A character encoding name to check.

    Returns boolean

Static join

  • join(separator?: string): string
  • Adds all the elements of an array separated by the specified separator string.

    Parameters

    • Optional separator: string

      A string used to separate one element of an array from the next in the resulting String. If omitted, the array elements are separated with a comma.

    Returns string

Static lastIndexOf

  • lastIndexOf(searchElement: number, fromIndex?: number): number
  • Returns the index of the last occurrence of a value in an array.

    Parameters

    • searchElement: number

      The value to locate in the array.

    • Optional fromIndex: number

      The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0.

    Returns number

Static map

  • map(callbackfn: function, thisArg?: any): Uint8Array
  • Calls a defined callback function on each element of an array, and returns an array that contains the results.

    Parameters

    • callbackfn: function

      A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.

        • (value: number, index: number, array: Uint8Array): number
        • Parameters

          • value: number
          • index: number
          • array: Uint8Array

          Returns number

    • Optional thisArg: any

      An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.

    Returns Uint8Array

Static reduce

  • reduce(callbackfn: function, initialValue?: number): number
  • reduce<U>(callbackfn: function, initialValue: U): U
  • Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.

    Parameters

    • callbackfn: function

      A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array.

        • (previousValue: number, currentValue: number, currentIndex: number, array: Uint8Array): number
        • Parameters

          • previousValue: number
          • currentValue: number
          • currentIndex: number
          • array: Uint8Array

          Returns number

    • Optional initialValue: number

      If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.

    Returns number

  • Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.

    Type parameters

    • U

    Parameters

    • callbackfn: function

      A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array.

        • (previousValue: U, currentValue: number, currentIndex: number, array: Uint8Array): U
        • Parameters

          • previousValue: U
          • currentValue: number
          • currentIndex: number
          • array: Uint8Array

          Returns U

    • initialValue: U

      If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.

    Returns U

Static reduceRight

  • reduceRight(callbackfn: function, initialValue?: number): number
  • reduceRight<U>(callbackfn: function, initialValue: U): U
  • Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.

    Parameters

    • callbackfn: function

      A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array.

        • (previousValue: number, currentValue: number, currentIndex: number, array: Uint8Array): number
        • Parameters

          • previousValue: number
          • currentValue: number
          • currentIndex: number
          • array: Uint8Array

          Returns number

    • Optional initialValue: number

      If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.

    Returns number

  • Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.

    Type parameters

    • U

    Parameters

    • callbackfn: function

      A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array.

        • (previousValue: U, currentValue: number, currentIndex: number, array: Uint8Array): U
        • Parameters

          • previousValue: U
          • currentValue: number
          • currentIndex: number
          • array: Uint8Array

          Returns U

    • initialValue: U

      If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.

    Returns U

Static reverse

  • reverse(): Uint8Array
  • Reverses the elements in an Array.

    Returns Uint8Array

Static set

  • set(index: number, value: number): void
  • set(array: ArrayLike<number>, offset?: number): void
  • Sets a value or an array of values.

    Parameters

    • index: number

      The index of the location to set.

    • value: number

      The value to set.

    Returns void

  • Sets a value or an array of values.

    Parameters

    • array: ArrayLike<number>

      A typed or untyped array of values to set.

    • Optional offset: number

      The index in the current array at which the values are to be written.

    Returns void

Static slice

  • slice(start?: number, end?: number): Uint8Array
  • Returns a section of an array.

    Parameters

    • Optional start: number

      The beginning of the specified portion of the array.

    • Optional end: number

      The end of the specified portion of the array.

    Returns Uint8Array

Static some

  • some(callbackfn: function, thisArg?: any): boolean
  • Determines whether the specified callback function returns true for any element of an array.

    Parameters

    • callbackfn: function

      A function that accepts up to three arguments. The some method calls the callbackfn function for each element in array1 until the callbackfn returns true, or until the end of the array.

        • (value: number, index: number, array: Uint8Array): boolean
        • Parameters

          • value: number
          • index: number
          • array: Uint8Array

          Returns boolean

    • Optional thisArg: any

      An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.

    Returns boolean

Static sort

  • sort(compareFn?: function)
  • Sorts an array.

    Parameters

    • Optional compareFn: function

      The name of the function used to determine the order of the elements. If omitted, the elements are sorted in ascending, ASCII character order.

        • (a: number, b: number): number
        • Parameters

          • a: number
          • b: number

          Returns number

Static subarray

  • subarray(begin: number, end?: number): Uint8Array
  • Gets a new Uint8Array view of the ArrayBuffer store for this array, referencing the elements at begin, inclusive, up to end, exclusive.

    Parameters

    • begin: number

      The index of the beginning of the array.

    • Optional end: number

      The index of the end of the array.

    Returns Uint8Array

Static toLocaleString

  • toLocaleString(): string
  • Converts a number to a string by using the current locale.

    Returns string

Static toString

  • toString(): string
  • Returns a string representation of an array.

    Returns string

Generated using TypeDoc