@adviser/cement - v0.0.0
    Preparing search index...

    Function coerceIntoUint8

    • Coerces various binary types into Uint8Array with Result-based error handling.

      Converts ArrayBuffer, ArrayBufferView, Node.js Buffer, or Result-wrapped values into Uint8Array. Returns Result.Err for unsupported types like Blob (use asyncCoerceIntoUint8 for Blobs). Handles Result-wrapped inputs by unwrapping and recursively coercing.

      Parameters

      • raw: ToUInt8

        Binary data to coerce (ArrayBuffer, TypedArray, Buffer, or Result-wrapped)

      Returns Result<Uint8Array<ArrayBufferLike>>

      Result.Ok with Uint8Array or Result.Err with error message

      // ArrayBuffer
      const result1 = coerceIntoUint8(new ArrayBuffer(10));
      if (result1.isOk()) {
      const bytes = result1.unwrap(); // Uint8Array
      }

      // TypedArray
      const result2 = coerceIntoUint8(new Int32Array([1, 2, 3]));

      // Result-wrapped input
      const wrapped = Result.Ok(new ArrayBuffer(5));
      const result3 = coerceIntoUint8(wrapped); // Unwraps and converts

      // Blob not supported (use asyncCoerceIntoUint8)
      const result4 = coerceIntoUint8(new Blob(['data']));
      // Returns Result.Err("Blob not supported")