Flusspferd API and module docs

class binary.ByteArray

Includes

Constructor

new binary.ByteArray(length)
new binary.ByteArray(bytes)
new binary.ByteArray(string[, charset="UTF-8"])
  • length (Number) – length of new string
  • bytes (Array | binary.Binary) – contents of new blob.

Create a new ByteArray. length creates a new ByteArray of this length where every byte is 0. bytes is either another blob to copy, or an array of byte values. The third form is constructed by encoding string to bytes using charset via the encodings module.

ByteArrays are mutable, both in terms of length and of the data contained within.

Instance methods

  • append #

    binary.ByteArray#append(args...) ⇒ Number
    • args (binary.Binary | Byte | Array) – data to append to this one

    Concatenate the provided arguments onto the end of the existing blob.

    Each argument must be a Byte, an Array of Bytes or another blob.

    Return the new length of the blob.

    Aliased as: binary.ByteArray#push

  • count #

    binary.ByteArray#count(callback[, thisobj]) ⇒ Number
    • callback (Function) – callback
    • thisobj (?) – invocant for callback

    Calls the provided callback function once for each byte in the blob, in order, returns the number of bytes for which callback returned a truthful value.

    The callback is called with arguments of:

    • byte (Number): the current byte
    • index (Number): the byte offset from the start of the array
    • blob (binary.ByteArray): the blob
  • displace #

    binary.ByteArray#displace(begin[, end[, args...]]) ⇒ Number
    • begin (Number) – start of range
    • end (Number) – end of range
    • args (binary.Binary | Byte | Array) – data to insert at begin.

    Remove the data in the range [begin, end), and optionally insert new data started at begin. Original data after end is preserved.

    Returns the new length of the blob. If you want the deleted data instead, use splice

    Note This method is perhaps badly named.

  • erase #

    binary.ByteArray#erase(begin[, end]) ⇒ Number
    • begin (Number) – start of range
    • end (Number) – end of range

    Erase a range of bytes [begin, end) form this blob. Bytes following end will be shifted down to start at index begin and the length will be reduced.

    Returns the new length of the blob.

  • every #

    binary.ByteArray#every(callback[, thisobj]) ⇒ Boolean
    • callback (Function) – callback
    • thisobj (?) – invocant for callback

    Invoke callback (with an invocant of thisobj if provided) and return true iff the callback returns a truthful value for every byte in the array.

    The callback is called with arguments of:

    • byte (Number): the current byte
    • index (Number): the byte offset from the start of the array
    • blob (binary.ByteArray): the blob
  • filter #

    binary.ByteArray#filter(callback[, thisobj]) ⇒ binary.ByteArray
    • callback (Function) – filter callback function
    • thisobj (?) – optional invocant for callback

    Calls the provided callback function for each byte in the blob, in order, and constructs a new blob containing only the bytes for which the callback returned a truthful value.

    The callback is called with arguments of:

    • byte (Number): the current byte
    • index (Number): the byte offset from the start of the array
    • blob (binary.ByteArray): the blob
  • forEach #

    binary.ByteArray#forEach(callback[, thisobj]) ⇒ undefined
    • callback (Function) – callback
    • thisobj (?) – invocant for callback

    Call the callback function once for each byte, in order, with the invocant optionally set to thisobj. The return value of the callback is ignored.

    The callback is called with arguments of:

    • byte (Number): the current byte
    • index (Number): the byte offset from the start of the array
    • blob (binary.ByteArray): the blob
  • insert #

    binary.ByteArray#insert(pos, args...) ⇒ Number
    • pos (Number) – position
    • args (binary.Binary | Byte | Array) – data to insert

    Insert data into the byte array before pos. Equivalent to calling blob.displace(pos,pos,args...)

    Returns the new length of the blob.

  • map #

    binary.ByteArray#map(callback[, thisobj]) ⇒ binary.ByteArray
    • callback (Function) – callback
    • thisobj (?) – invocant for callback

    Calls the provided callback function once for each byte in the blob, in order, and constructs a new blob from the results. The callback must return something that could be passed to binary.ByteArray.append which means that the new byte array could be longer or shorter then the original.

    The callback is called with arguments of:

    • byte (Number): the current byte
    • index (Number): the byte offset from the start of the array
    • blob (binary.ByteArray): the blob
  • pop #

    binary.ByteArray#pop() ⇒ Byte

    Remove the final byte from the blob and return it. If the blob is empty an exception will be thrown.

    This doesn’t make a huge amount of sense on a ByteArray.

  • prepend #

    binary.ByteArray#prepend(args...) ⇒ Number
    • args (binary.Binary | Byte | Array) – data to append to this one

    Prepend the concatenation of the provided arguments to the contents of this blob.

    Return the new length of the blob.

    Aliased as: binary.ByteArray#unshift

  • push #

    binary.ByteArray#push(args...) ⇒ Number
    • args (binary.Binary | Byte | Array) – data to append to this blob

    Provided for API compatibility with Array.

    Alias of: binary.ByteArray#append

  • reduce #

    binary.ByteArray#reduce(callback[, initialValue]) ⇒ ?
    • callback (Function) – callback
    • initialValue (?) – initial value passed to callback

    Apply a function against an accumulator and each byte of the blob (from left-to-right) as to reduce it to a single value.

    Executes the callback function once for each blob in the blob, receiving four arguments: the initial value (or value from the previous callback call), the current byte, the current index, and the blob over which iteration is occurring.

    The return value is whaterver is returned from the last iteration.

    The callback is called with arguments of:

    • value (?): value returned from previous callback, or initialValue.
    • byte (Number): the current byte
    • index (Number): the byte offset from the start of the array
    • blob (binary.ByteArray): the blob
  • reduceRight #

    binary.ByteArray#reduceRight(callback[, initialValue]) ⇒ ?

    Apply a function against an accumulator and each byte of the blob (from right-to-left) as to reduce it to a single value. See reduce for a more detailed description.

  • reverse #

    binary.ByteArray#reverse() ⇒ binary.ByteArray

    Reverse the order of the bytes of this array in-place, and return it.

    This behaves the same as Array#reverse.

    This doesn’t make a huge amount of sense on a ByteArray.

  • shift #

    binary.ByteArray#shift() ⇒ Number

    Remove and return the first byte of the blob. Will throw an exception if it is empty.

    This doesn’t make a huge amount of sense on a ByteArray.

  • some #

    binary.ByteArray#some(callback[, thisobj]) ⇒ Boolean
    • callback (Function) – callback
    • thisobj (?) – invocant for callback

    Calls the provided callback function for each byte in the blob, in order, and returns true as soon as the callback returns a truthful value. Will return false if no true value is returned.

    The callback is called with arguments of:

    • byte (Number): the current byte
    • index (Number): the byte offset from the start of the array
    • blob (binary.ByteArray): the blob
  • sort #

    binary.ByteArray#sort([sorter]) ⇒ binary.ByteArray
    • sorter (Function) – comparision function

    This behaves the same as Array#sort.

    This doesn’t make a huge amount of sense on a ByteArray.

  • splice #

    binary.ByteArray#splice(begin[, end[, args...]]) ⇒ binary.ByteArray
    • begin (Number) – start of range
    • end (Number) – end of range
    • args (binary.Binary | Byte | Array) – data to insert

    Remove the data in the range [begin, end), and optionally insert new data started at begin. Original data after end is preserved.

    This method is similar to displace but it returns the removed bytes instead of the new length.

  • unshift #

    binary.ByteArray#unshift(args...) ⇒ Number
    • args (binary.Binary | Byte | Array) – data to prepend to this one

    Insert new data before the start of the current data

    Return the new length of the blob.

    Alias of: binary.ByteArray#prepend