UNPKG

itk-wasm

Version:

High-performance spatial analysis in a web browser, Node.js, and reproducible execution across programming languages and hardware architectures.

74 lines 2.29 kB
import IntTypes from './interface-types/int-types.js'; import FloatTypes from './interface-types/float-types.js'; function bufferToTypedArray(wasmType, buffer) { let typedArray = null; switch (wasmType) { case IntTypes.UInt8: { typedArray = new Uint8Array(buffer); break; } case IntTypes.Int8: { typedArray = new Int8Array(buffer); break; } case IntTypes.UInt16: { typedArray = new Uint16Array(buffer); break; } case IntTypes.Int16: { typedArray = new Int16Array(buffer); break; } case IntTypes.UInt32: { typedArray = new Uint32Array(buffer); break; } case IntTypes.Int32: { typedArray = new Int32Array(buffer); break; } case IntTypes.UInt64: { if (typeof globalThis.BigUint64Array === 'function') { typedArray = new BigUint64Array(buffer); } else { // Sub with reasonable default. Will get cast to Uint8Array when // transferred to WebAssembly. typedArray = new Uint8Array(buffer); } break; } case IntTypes.Int64: { if (typeof globalThis.BigInt64Array === 'function') { typedArray = new BigInt64Array(buffer); } else { // Sub with reasonable default. Will get cast to Uint8Array when // transferred to WebAssembly. typedArray = new Uint8Array(buffer); } break; } case FloatTypes.Float32: { typedArray = new Float32Array(buffer); break; } case FloatTypes.Float64: { typedArray = new Float64Array(buffer); break; } case 'null': { typedArray = null; break; } case null: { typedArray = null; break; } default: throw new Error('Type is not supported as a TypedArray'); } return typedArray; } export default bufferToTypedArray; //# sourceMappingURL=buffer-to-typed-array.js.map