rhodonite
    Preparing search index...

    Class DataUtil

    Utility class for data manipulation, conversion, and processing operations. Provides methods for handling various data formats including ArrayBuffer, Uint8Array, base64 encoding/decoding, image processing, and file operations.

    Index

    Constructors

    Properties

    crc32table: string[] = ...

    CRC32 lookup table for checksum calculations.

    Methods

    • Converts ArrayBuffer or Uint8Array to an image data URL.

      Parameters

      • arrayBuffer: ArrayBuffer | Uint8Array<ArrayBufferLike>

        The image data buffer

      • imageType: string

        Type/format of the image

      Returns string

      Data URL string for the image

    • Accesses binary data from a buffer view and converts it to an image data URL.

      Parameters

      • bufferViewIndex: number

        Index of the buffer view in the JSON

      • json: any

        JSON object containing buffer view information

      • buffer: ArrayBuffer | Uint8Array<ArrayBufferLike>

        The source buffer data

      • mimeType: string

        MIME type of the image

      Returns string

      Data URL string for the image

    • Adds padding bytes to achieve the specified byte alignment.

      Parameters

      • originalByteLength: number

        The original byte length

      • byteAlign: number

        The byte alignment requirement

      Returns number

      The padded byte length

    • Converts an ArrayBuffer to a string using TextDecoder when available.

      Parameters

      • arrayBuffer: ArrayBuffer

        The ArrayBuffer to convert

      Returns string

      String representation of the buffer data

    • Decodes a base64 string, compatible with both browser and Node.js environments.

      Parameters

      • str: string

        The base64 string to decode

      Returns string

      Decoded binary string

    • Converts a base64 string to an ArrayBuffer (browser environment only).

      Parameters

      • base64: string

        The base64 string to convert

      Returns ArrayBuffer

      ArrayBuffer containing the decoded data

      Error if not running in browser environment

    • Encodes a string to base64 format, compatible with both browser and Node.js environments.

      Parameters

      • str: string

        The string to encode

      Returns string

      Base64 encoded string

    • Calculates the number of padding bytes needed for byte alignment.

      Parameters

      • originalByteLength: number

        The original byte length

      • byteAlign: number

        The byte alignment requirement

      Returns number

      Number of padding bytes needed

    • Copies data from source ArrayBuffer to destination ArrayBuffer.

      Parameters

      • param0: {
            copyByteLength: number;
            dist: ArrayBuffer;
            distByteOffset: number;
            src: ArrayBuffer;
            srcByteOffset: number;
        }

        Copy configuration object

        • copyByteLength: number

          Number of bytes to copy

        • dist: ArrayBuffer

          Destination ArrayBuffer

        • distByteOffset: number

          Byte offset in destination buffer (default: 0)

        • src: ArrayBuffer

          Source ArrayBuffer

        • srcByteOffset: number

          Byte offset in source buffer

      Returns ArrayBuffer

      The destination ArrayBuffer

    • Copies data using 4-byte aligned operations from source to destination ArrayBuffer.

      Parameters

      • param0: {
            copyByteLength: number;
            dist: ArrayBuffer;
            distByteOffset: number;
            src: ArrayBuffer;
            srcByteOffset: number;
        }

        Copy configuration object

        • copyByteLength: number

          Number of bytes to copy (must be 4-byte aligned)

        • dist: ArrayBuffer

          Destination ArrayBuffer

        • distByteOffset: number

          Byte offset in destination buffer (must be 4-byte aligned)

        • src: ArrayBuffer

          Source ArrayBuffer

        • srcByteOffset: number

          Byte offset in source buffer (must be 4-byte aligned)

      Returns ArrayBuffer

      The destination ArrayBuffer

      Error if byte offsets are not 4-byte aligned

    • Copies data using 4-byte aligned operations with padding to achieve 4-byte alignment.

      Parameters

      • param0: {
            copyByteLength: number;
            dist: ArrayBuffer;
            distByteOffset: number;
            src: ArrayBuffer;
            srcByteOffset: number;
        }

        Copy configuration object

        • copyByteLength: number

          Number of bytes to copy

        • dist: ArrayBuffer

          Destination ArrayBuffer

        • distByteOffset: number

          Byte offset in destination buffer

        • src: ArrayBuffer

          Source ArrayBuffer

        • srcByteOffset: number

          Byte offset in source buffer

      Returns ArrayBuffer

      The destination ArrayBuffer

    • Copies data from source ArrayBuffer to destination ArrayBuffer with padding if needed.

      Parameters

      • param0: {
            copyByteLength: number;
            dist: ArrayBuffer;
            distByteOffset: number;
            src: ArrayBuffer;
            srcByteOffset: number;
        }

        Copy configuration object

        • copyByteLength: number

          Number of bytes to copy

        • dist: ArrayBuffer

          Destination ArrayBuffer

        • distByteOffset: number

          Byte offset in destination buffer

        • src: ArrayBuffer

          Source ArrayBuffer

        • srcByteOffset: number

          Byte offset in source buffer

      Returns ArrayBuffer

      The destination ArrayBuffer

    • Creates a blob image URI from a Uint8Array.

      Parameters

      • uint8Array: Uint8Array

        The image data as Uint8Array

      • mimeType: string

        MIME type of the image

      Returns string

      Blob URL string for the image

    • Creates an HTMLImageElement from a URI with proper CORS handling.

      Parameters

      • uri: string

        The image URI

      • mimeType: string

        MIME type of the image

      Returns RnPromise<HTMLImageElement>

      Promise that resolves to the loaded HTMLImageElement

    • Creates a Uint8Array from buffer view information in glTF or RnM2 format.

      Parameters

      • json: glTF1 | RnM2

        The JSON object containing buffer view information

      • bufferViewIndex: number

        Index of the buffer view

      • buffer: ArrayBuffer | Uint8Array<ArrayBufferLike>

        The source buffer data

      Returns Uint8Array

      Uint8Array view of the specified buffer region

    • Converts a data URI to an ArrayBuffer.

      Parameters

      • dataUri: string

        The data URI string to convert

      Returns ArrayBuffer

      ArrayBuffer containing the decoded data

    • Detects if an image contains transparent pixels below a specified threshold.

      Parameters

      • image: ImageData | HTMLImageElement | HTMLCanvasElement

        The image to analyze (HTMLImageElement, HTMLCanvasElement, or ImageData)

      • threshold: number = 1.0

        Alpha threshold value (default: 1.0)

      Returns boolean

      True if transparent pixels are found, false otherwise

    • Fetches an ArrayBuffer from a URI using the Fetch API.

      Parameters

      • uri: string

        The URI to fetch from

      Returns Promise<Result<ArrayBuffer, unknown>>

      Promise that resolves to a Result containing the ArrayBuffer or error

    • Creates a copy of an ArrayBuffer with specified parameters.

      Parameters

      • param0: {
            copyByteLength: number;
            distByteOffset: number;
            src: ArrayBuffer;
            srcByteOffset: number;
        }

        Copy configuration object

        • copyByteLength: number

          Number of bytes to copy

        • distByteOffset: number

          Byte offset in destination buffer

        • src: ArrayBuffer

          Source ArrayBuffer

        • srcByteOffset: number

          Byte offset in source buffer

      Returns ArrayBuffer

      Copied ArrayBuffer

    • Creates a copy of an ArrayBuffer using 4-byte aligned operations.

      Parameters

      • param0: {
            copyByteLength: number;
            distByteOffset: number;
            src: ArrayBuffer;
            srcByteOffset: number;
        }

        Copy configuration object

        • copyByteLength: number

          Number of bytes to copy (must be 4-byte aligned)

        • distByteOffset: number

          Byte offset in destination buffer (must be 4-byte aligned)

        • src: ArrayBuffer

          Source ArrayBuffer

        • srcByteOffset: number

          Byte offset in source buffer (must be 4-byte aligned)

      Returns ArrayBuffer

      Copied ArrayBuffer

      Error if byte offsets are not 4-byte aligned

    • Extracts the file extension from a filename.

      Parameters

      • fileName: string

        The filename to extract extension from

      Returns string

      File extension string

    • Gets the appropriate data URL prefix for a given image type.

      Parameters

      • imageType: string

        The image type or MIME type

      Returns string

      Data URL prefix string

    • Gets the MIME type from a file extension.

      Parameters

      • extension: string

        The file extension

      Returns string

      MIME type string

    • Gets the nearest power of two value for a given number.

      Parameters

      • x: number

        The input value

      Returns number

      The nearest power of two value

    • Resizes an image to fit within specified dimensions while maintaining aspect ratio.

      Parameters

      • image: HTMLImageElement

        The source HTMLImageElement

      • maxSize: number

        Maximum size for the largest dimension

      Returns [HTMLCanvasElement, number, number]

      Tuple containing the resized canvas, width, and height

    • Determines if the current environment is Node.js.

      Returns boolean

      True if running in Node.js environment, false otherwise

    • Loads a resource asynchronously with support for both binary and text data.

      Parameters

      • resourceUri: string

        URI of the resource to load

      • isBinary: boolean

        Whether to load as binary data

      • resolveCallback: Function

        Callback function for successful loading

      • rejectCallback: Function

        Callback function for error handling

      Returns Promise<any>

      Promise that resolves with the loaded resource

    • Converts normalized Int16Array values to Float32Array.

      Parameters

      • from: number[] | Int16Array<ArrayBufferLike>

        Source Int16Array or number array

      Returns Float32Array<ArrayBuffer>

      Float32Array with normalized values

    • Converts normalized Int8Array values to Float32Array.

      Parameters

      • from: number[] | Int8Array<ArrayBufferLike>

        Source Int8Array or number array

      Returns Float32Array<ArrayBuffer>

      Float32Array with normalized values

    • Converts normalized Uint16Array values to Float32Array.

      Parameters

      • from: number[] | Uint16Array<ArrayBufferLike>

        Source Uint16Array or number array

      Returns Float32Array<ArrayBuffer>

      Float32Array with normalized values

    • Converts normalized Uint8Array values to Float32Array.

      Parameters

      • from: number[] | Uint8Array<ArrayBufferLike>

        Source Uint8Array or number array

      Returns Float32Array<ArrayBuffer>

      Float32Array with normalized values

    • Converts a string to base64 encoding.

      Parameters

      • str: string

        The string to encode

      Returns string

      Base64 encoded string

    • Converts a string to an ArrayBuffer using TextEncoder.

      Parameters

      • src: string

        The string to convert

      Returns ArrayBuffer

      ArrayBuffer containing the encoded string data

    • Extracts a Uint8Array from a buffer view based on JSON specification.

      Parameters

      • json: RnM2

        RnM2 JSON object containing buffer view information

      • bufferViewIndex: number

        Index of the buffer view

      • buffer: ArrayBuffer | Uint8Array<ArrayBufferLike>

        The source buffer data

      Returns Uint8Array

      Uint8Array view of the specified buffer region

    • Calculates CRC32 checksum for a given string.

      Parameters

      • str: string

        The string to calculate checksum for

      Returns number

      CRC32 checksum as unsigned 32-bit integer

    • Converts a Uint8Array to a data URL for image display.

      Parameters

      • uint8array: Uint8Array

        The image data as Uint8Array

      • width: number

        Image width in pixels

      • height: number

        Image height in pixels

      Returns string

      Data URL string for the image

    • Converts a Uint8Array to a string using TextDecoder when available.

      Parameters

      • uint8Array: Uint8Array

        The Uint8Array to convert

      Returns string

      String representation of the array data

    • Internal method to convert Uint8Array to string without TextDecoder.

      Parameters

      • uint8: Uint8Array

        The Uint8Array to convert

      Returns string

      String representation of the array data