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 { + const array = await this.storage.getItem( + 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 }); + } }