
The AracnaFile class extends the AracnaBlob class and is built on top of the File class.
lastModified property.The resolveArrayBuffer method resolves the data contained in the File as an ArrayBuffer.
import { AracnaFile } from '@aracna/core';
(async () => {
let binary, file;
binary = new Uint8Array([
0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x2c, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64
]);
file = new AracnaFile(new File([binary], 'file.bin'));
await file.resolveArrayBuffer();
// will log ArrayBuffer
console.log(file.arrayBuffer);
// will log Uint8Array
console.log(file.uInt8Array);
})();The resolveText method resolves the data contained in the File as a string.
import { AracnaFile } from '@aracna/core';
(async () => {
let file;
file = new AracnaFile(new File(['hello'], 'file.txt'));
await file.resolveText();
// will log "hello"
console.log(file.text);
// will log Uint8Array
console.log(file.uInt8Array);
})();To read the data contained in the File as a Uint8Array, you need to call either the resolveArrayBuffer or resolveText method before accessing the uInt8Array property.
import { AracnaFile } from '@aracna/core';
(async () => {
let file;
file = new AracnaFile(new File(['hello'], 'file.txt'));
await file.resolveText();
// will log Uint8Array
console.log(file.uInt8Array);
})();In the AracnaFile 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 { AracnaFile } from '@aracna/core';
(async () => {
let file, serialized, deserialized;
file = new AracnaFile(new File(['hello'], 'file.txt'));
await file.resolveText();
// will log "file.txt"
console.log(file.name);
// will log "hello"
console.log(file.text);
// will log Uint8Array
console.log(file.uInt8Array);
serialized = JSON.stringify(file, null, 2);
// will log JSON string
console.log(serialized);
deserialized = new AracnaFile(JSON.parse(serialized));
// will log AracnaFile
console.log(deserialized);
// will log "file.txt"
console.log(deserialized.name);
// will log "hello"
console.log(deserialized.text);
// will log Uint8Array
console.log(deserialized.uInt8Array);
})();