Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

feat: add readChunk & toBlob functions to filehandle

thecodrr7ac80384e01f
diff --git a/apps/web/packages/streamablefs/src/filehandle.ts b/apps/web/packages/streamablefs/src/filehandle.ts
index 8ec63958c..7f2a720b5 100644
--- a/apps/web/packages/streamablefs/src/filehandle.ts
+++ b/apps/web/packages/streamablefs/src/filehandle.ts
@@ -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 });
+ }
}