mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-02-24 04:00:59 +01:00
fs: add chunkSize method for faster file size calculation
This commit is contained in:
committed by
Abdullah Atta
parent
5a49941003
commit
cb52b390ab
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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[]>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user