mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 23:19:40 +01:00
feat: add readChunk & toBlob functions to filehandle
This commit is contained in:
@@ -37,4 +37,21 @@ export default class FileHandle extends ReadableStream {
|
||||
private getChunkKey(offset: number): string {
|
||||
return `${this.file.filename}-chunk-${offset}`;
|
||||
}
|
||||
|
||||
async readChunk(offset: number): Promise<Uint8Array | null> {
|
||||
const array = await this.storage.getItem<Uint8Array>(
|
||||
this.getChunkKey(offset)
|
||||
);
|
||||
return array;
|
||||
}
|
||||
|
||||
async toBlob() {
|
||||
let blobParts: BlobPart[] = [];
|
||||
for (let i = 0; i < this.file.chunks; ++i) {
|
||||
const array = await this.readChunk(i);
|
||||
if (!array) continue;
|
||||
blobParts.push(array.buffer);
|
||||
}
|
||||
return new Blob(blobParts, { type: this.file.type });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user