Class (GI Struct)

GLib-2.0GLibByteArray

Contains the public fields of a GLib.ByteArray.

Index

Constructors

Properties

data: number
len: number

Methods

  • Adds the given bytes to the end of the GLib.ByteArray. The array will grow in size automatically if necessary.

    Parameters

    • array: string | Uint8Array<ArrayBufferLike>

      a byte array

    • data: string | Uint8Array<ArrayBufferLike>

      the byte data to be added

    Returns Uint8Array

  • Frees the memory allocated by the GLib.ByteArray. If free_segment is true it frees the actual byte data. If the reference count of array is greater than one, the GLib.ByteArray wrapper is preserved but the size of array will be set to zero.

    Parameters

    • array: string | Uint8Array<ArrayBufferLike>

      a byte array

    • free_segment: boolean

      if true, the actual byte data is freed as well

    Returns Uint8Array<ArrayBufferLike>

  • Creates a byte array containing the data. After this call, data belongs to the GLib.ByteArray and may no longer be modified by the caller. The memory of data has to be dynamically allocated and will eventually be freed with GLib.free.

    Do not use it if len is greater than G_MAXUINT. GLib.ByteArray stores the length of its data in guint, which may be shorter than gsize.

    Parameters

    • data: string | Uint8Array<ArrayBufferLike>

      the byte data for the array

    Returns Uint8Array

  • Adds the given data to the start of the GLib.ByteArray. The array will grow in size automatically if necessary.

    Parameters

    • array: string | Uint8Array<ArrayBufferLike>

      a byte array

    • data: string | Uint8Array<ArrayBufferLike>

      the byte data to be added

    Returns Uint8Array

  • Atomically increments the reference count of array by one. This function is thread-safe and may be called from any thread.

    Parameters

    • array: string | Uint8Array<ArrayBufferLike>

      a byte array

    Returns Uint8Array

  • Removes the byte at the given index from a GLib.ByteArray. The following bytes are moved down one place.

    Parameters

    • array: string | Uint8Array<ArrayBufferLike>

      a byte array

    • index_: number

      the index of the byte to remove

    Returns Uint8Array

  • Removes the byte at the given index from a GLib.ByteArray. The last element in the array is used to fill in the space, so this function does not preserve the order of the GLib.ByteArray. But it is faster than GLib.ByteArray.remove_index.

    Parameters

    • array: string | Uint8Array<ArrayBufferLike>

      a byte array

    • index_: number

      the index of the byte to remove

    Returns Uint8Array

  • Removes the given number of bytes starting at the given index from a GLib.ByteArray. The following elements are moved to close the gap.

    Parameters

    • array: string | Uint8Array<ArrayBufferLike>

      a byte array

    • index_: number

      the index of the first byte to remove

    • length: number

      the number of bytes to remove

    Returns Uint8Array

  • Sets the size of the GLib.ByteArray, expanding it if necessary.

    Parameters

    • array: string | Uint8Array<ArrayBufferLike>

      a byte array

    • length: number

      the new size of the GLib.ByteArray

    Returns Uint8Array

  • Creates a new GLib.ByteArray with reserved_size bytes preallocated. This avoids frequent reallocation, if you are going to add many bytes to the array. Note however that the size of the array is still 0.

    Parameters

    • reserved_size: number

      the number of bytes preallocated

    Returns Uint8Array

  • Sorts a byte array, using compare_func which should be a qsort()-style comparison function (returns less than zero for first arg is less than second arg, zero for equal, greater than zero if first arg is greater than second arg).

    If two array elements compare equal, their order in the sorted array is undefined. If you want equal elements to keep their order (i.e. you want a stable sort) you can write a comparison function that, if two elements would otherwise compare equal, compares them by their addresses.

    Parameters

    • array: string | Uint8Array<ArrayBufferLike>

      a byte array

    • compare_func: CompareFunc

      the comparison function

    Returns void

  • Frees the data in the array and resets the size to zero, while the underlying array is preserved for use elsewhere and returned to the caller.

    Parameters

    • array: string | Uint8Array<ArrayBufferLike>

      a byte array

    Returns Uint8Array

  • Atomically decrements the reference count of array by one. If the reference count drops to 0, all memory allocated by the array is released. This function is thread-safe and may be called from any thread.

    Parameters

    • array: string | Uint8Array<ArrayBufferLike>

      a byte array

    Returns void