Skip to content
This repository was archived by the owner on Mar 3, 2026. It is now read-only.
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 2 additions & 17 deletions src/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,6 @@ export enum FileExceptionMessages {
UPLOAD_MISMATCH = `The uploaded data did not match the data from the server.
As a precaution, the file has been deleted.
To be sure the content is the same, you should try uploading the file again.`,
STREAM_NOT_READABLE = 'Stream must be readable.',
}

/**
Expand Down Expand Up @@ -3644,20 +3643,6 @@ class File extends ServiceObject<File, FileMetadata> {
}
const returnValue = retry(
async (bail: (err: Error) => void) => {
if (data instanceof Readable) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this logic as for the vast majority it would simply slow down their uploads unnecessarily. Additionally, later versions of Node.js catch this for us.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know what versions catch this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Node 18.0.0:

Here's a simple reproduction for a REPL (anything before 18 the console.log isn't called):

const readable = stream.Readable({read() {this.push(null)}});
readable.read();
readable.readable // false
stream.pipeline(readable, stream.PassThrough, () => console.log('done'));

// Make sure any pending async readable operations are finished before
// attempting to check if the stream is readable.
await new Promise(resolve => setImmediate(resolve));

if (!data.readable || data.destroyed) {
// Calling pipeline() with a non-readable stream will result in the
// callback being called without an error, and no piping taking
// place. In that case, file.save() would appear to succeed, but
// nothing would be uploaded.
return bail(new Error(FileExceptionMessages.STREAM_NOT_READABLE));
}
}

return new Promise<void>((resolve, reject) => {
if (maxRetries === 0) {
this.storage.retryOptions.autoRetry = false;
Expand All @@ -3673,10 +3658,10 @@ class File extends ServiceObject<File, FileMetadata> {
!this.storage.retryOptions.autoRetry ||
!this.storage.retryOptions.retryableErrorFn!(err)
) {
bail(err);
return reject(err);
}

reject(err);
return bail(err);
};

if (typeof data === 'string' || Buffer.isBuffer(data)) {
Expand Down