Skip to content

Commit

Permalink
fix (diced#350): Return size 0 for not found
Browse files Browse the repository at this point in the history
  • Loading branch information
TacticalTechJay committed Apr 25, 2023
1 parent a680168 commit 4ab1555
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/lib/datasources/S3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,22 @@ export class S3 extends Datasource {
}

public size(file: string): Promise<number> {
return new Promise((res, rej) => {
return new Promise((res) => {
this.s3.statObject(this.config.bucket, file, (err, stat) => {
if (err) rej(err);
if (err) res(0);
else res(stat.size);
});
});
}

public async fullSize(): Promise<number> {
return new Promise((res, rej) => {
return new Promise((res) => {
const objects = this.s3.listObjectsV2(this.config.bucket, '', true);
let size = 0;

objects.on('data', (item) => (size += item.size));
objects.on('end', (err) => {
if (err) rej(err);
if (err) res(0);
else res(size);
});
});
Expand Down

0 comments on commit 4ab1555

Please sign in to comment.