Skip to content

Commit

Permalink
fix: empty binary list cause error
Browse files Browse the repository at this point in the history
  • Loading branch information
linonetwo committed Feb 11, 2024
1 parent c4f713d commit 027aaf1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/services/ImportService/ExpoReadStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class ExpoReadStream extends Readable {
this.chunkSize = options.length ?? 1024 * 1024 * 5;
}

public async init() {
public async init(): Promise<number> {
try {
const fileInfo = await fs.getInfoAsync(this.fileUri, { size: true });
if (fileInfo.exists) {
Expand All @@ -34,8 +34,10 @@ export class ExpoReadStream extends Readable {
if (this.fileSize === 0) {
console.warn(`File size is 0, Exist: ${String(fileInfo.exists)}, path: ${this.fileUri}`);
}
return this.fileSize;
} catch (error) {
this.emit('error', error);
return this.fileSize;
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/services/ImportService/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,12 @@ export class ImportService {
readStream.on('progress', (progress: number) => {
setProgress.setReadListProgress(progress);
});
await readStream.init();
const fileSize = await readStream.init();
if (fileSize <= 2) {
// 2 means `[]`, empty array
console.log('loadBinaryTiddlersAsFilesFromServer: No binary tiddlers to load.');
return;
}
const countBinaryTiddlerFieldsStream = chain([
readStream,
StreamArray.withParser(),
Expand Down

0 comments on commit 027aaf1

Please sign in to comment.