fs: add chunkSize method for faster file size calculation

This commit is contained in:
Abdullah Atta
2024-08-13 14:58:40 +05:00
committed by Abdullah Atta
parent 5a49941003
commit cb52b390ab
2 changed files with 4 additions and 3 deletions

View File

@@ -101,9 +101,9 @@ export default class FileHandle {
async size() {
let size = 0;
for (const chunk of this.chunks) {
const array = await this.storage.readChunk(chunk);
if (!array) continue;
size += array.length;
const length = await this.storage.chunkSize(chunk);
if (!length) throw new Error(`Found 0 byte sized chunk.`);
size += length;
}
return size;
}

View File

@@ -43,6 +43,7 @@ export interface IFileStorage {
writeChunk(chunkName: string, data: Uint8Array): Promise<void>;
deleteChunk(chunkName: string): Promise<void>;
readChunk(chunkName: string): Promise<Uint8Array | undefined>;
chunkSize(chunkName: string): Promise<number>;
listChunks(chunkPrefix: string): Promise<string[]>;
list(): Promise<string[]>;
}