Bun

namespace

unsafe

namespace unsafe

  • buffer: ArrayBufferLike | Uint8Array<ArrayBufferLike>
    ): string;

    Cast bytes to a String without copying. This is the fastest way to get a String from a Uint8Array or ArrayBuffer.

    Only use this for ASCII strings. If there are non-ascii characters, your application may crash and/or very confusing bugs will happen such as "foo" !== "foo".

    The input buffer must not be garbage collected. That means you will need to hold on to it for the duration of the string's lifetime.

    buffer: Uint16Array
    ): string;

    Cast bytes to a String without copying. This is the fastest way to get a String from a Uint16Array

    The input must be a UTF-16 encoded string. This API does no validation whatsoever.

    The input buffer must not be garbage collected. That means you will need to hold on to it for the duration of the string's lifetime.

  • level?: 0 | 1 | 2
    ): 0 | 1 | 2;

    Force the garbage collector to run extremely often, especially inside bun:test.

    • 0: default, disable
    • 1: asynchronously call the garbage collector more often
    • 2: synchronously call the garbage collector more often.

    This is a global setting. It's useful for debugging seemingly random crashes.

    BUN_GARBAGE_COLLECTOR_LEVEL environment variable is also supported.

    @returns

    The previous level

  • function mimallocDump(): void;

    Dump the mimalloc heap to the console