Skip to content

Commit

Permalink
Create new helper for validation
Browse files Browse the repository at this point in the history
  • Loading branch information
neos1803 committed Aug 20, 2021
1 parent 4cd013c commit 481db27
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/utils/validation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export function fileSizeValidation(stream?: any, maxSize?: number, callback?): Promise<any> {

return new Promise((resolve, reject) => {
let bytes=0;

stream.on("data", (chunk) => {
bytes += chunk.length;
});

stream.on("end", () => {
if (bytes > maxSize) {
reject(`File exceeds the maximum size ${maxSize}`);
} else {
resolve(bytes);
}
});

stream.on("error", (e) => {
reject(e);
});
});

}

0 comments on commit 481db27

Please sign in to comment.