
The AracnaBlob class is built on top of the Blob class.
The resolveArrayBuffer method resolves the data contained in the Blob as an ArrayBuffer.
import { AracnaBlob } from '@aracna/core';
(async () => {
let binary, blob;
binary = new Uint8Array([
0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x2c, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64
]);
blob = new AracnaBlob(new Blob([binary]));
await blob.resolveArrayBuffer();
// will log ArrayBuffer
console.log(blob.arrayBuffer);
// will log Uint8Array
console.log(blob.uInt8Array);
})();The resolveText method resolves the data contained in the Blob as a string.
import { AracnaBlob } from '@aracna/core';
(async () => {
let blob;
blob = new AracnaBlob(new Blob(['hello']));
await blob.resolveText();
// will log "hello"
console.log(blob.text);
// will log Uint8Array
console.log(blob.uInt8Array);
})();To read the data contained in the Blob as a Uint8Array, you need to call either the resolveArrayBuffer or resolveText method before accessing the uInt8Array property.
import { AracnaBlob } from '@aracna/core';
(async () => {
let blob;
blob = new AracnaBlob(new Blob(['hello']));
await blob.resolveText();
// will log Uint8Array
console.log(blob.uInt8Array);
})();In the AracnaBlob class, JSON serialization and deserialization are used to convert the instance into a JSON object and create an instance from a JSON object.
The resolveArrayBuffer or resolveText method must be called before serializing the instance.
import { AracnaBlob } from '@aracna/core';
(async () => {
let blob, serialized, deserialized;
blob = new AracnaBlob(new Blob(['hello']));
await blob.resolveText();
// will log "hello"
console.log(blob.text);
// will log Uint8Array
console.log(blob.uInt8Array);
serialized = JSON.stringify(blob, null, 2);
// will log JSON string
console.log(serialized);
deserialized = new AracnaBlob(JSON.parse(serialized));
// will log AracnaBlob
console.log(deserialized);
// will log "hello"
console.log(deserialized.text);
// will log Uint8Array
console.log(deserialized.uInt8Array);
})();