Skip to content

Commit

Permalink
fix: do not try to slice in chunk larger than the File itself
Browse files Browse the repository at this point in the history
Signed-off-by: John Molakvoæ <[email protected]>
  • Loading branch information
skjnldsv committed Jan 23, 2024
1 parent b4b1120 commit cd6a63e
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/utils/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ export const uploadData = async function(
* garbage collection
*/
export const getChunk = function(file: File, start: number, length: number): Promise<Blob> {
if (file.size <= start + length) {
return Promise.resolve(new Blob([file], { type: file.type }))
}

// Since we use a global FileReader, we need to only read one chunk at a time
return readerLimit(() => new Promise((resolve, reject) => {
reader.onload = () => {
Expand Down

0 comments on commit cd6a63e

Please sign in to comment.