Skip to content

Commit

Permalink
fix: If ReadableStream fails to read (e.g. WebKit + Big Boi Files), n…
Browse files Browse the repository at this point in the history
…otify as an error.
  • Loading branch information
cjpillsbury committed Apr 18, 2024
1 parent 2181381 commit dc93b1d
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/upchunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export type ChunkedStreamIterableOptions = {
export class ChunkedStreamIterable implements AsyncIterable<Blob> {
protected _chunkSize: number | undefined;
protected defaultChunkSize: number;
protected _error: Error | undefined;
public readonly minChunkSize: number;
public readonly maxChunkSize: number;

Expand Down Expand Up @@ -86,6 +87,10 @@ export class ChunkedStreamIterable implements AsyncIterable<Blob> {
return this.chunkSize * 1024;
}

get error() {
return this._error;
}

async *[Symbol.asyncIterator](): AsyncIterator<Blob> {
let chunk;
const reader = this.readableStream.getReader();
Expand Down Expand Up @@ -129,6 +134,9 @@ export class ChunkedStreamIterable implements AsyncIterable<Blob> {
}
}
}
} catch (e) {
// There are edge case errors when attempting to read() from ReadableStream reader.
this._error = e;
} finally {
// Last chunk, if any bits remain
if (chunk) {
Expand Down Expand Up @@ -705,6 +713,11 @@ export class UpChunk {
if (chunk) {
chunkUploadSuccess = await this.sendChunkWithRetries(chunk);
}

if (this.chunkedStreamIterable.error) {
this.dispatch('error', { message: `Unable to read file of size ${this.file.size} bytes. Try loading from another browser.` });
chunkUploadSuccess = false;
}
// NOTE: Need to disambiguate "last chunk to upload" (done) vs. "successfully"
// uploaded last chunk to upload" (depends on status of sendChunkWithRetries),
// specifically for "pending chunk" cases for the last chunk.
Expand Down

0 comments on commit dc93b1d

Please sign in to comment.