-
Notifications
You must be signed in to change notification settings - Fork 591
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
prefer duck-type checks over instanceof - Upload doesn't support polyfills/compat shims for Readable/ReadableStream #6153
Comments
Hi @jedwards1211 - thanks for reaching out. This was brought up to team discussion and as we all understand, this's because Best, |
I mainly wanted to help other library users avoid having an annoying debugging session with archiver or other libraries that use polyfills. I've talked to archiver about, at the very least, explaining this clearly in their docs. But, people don't always read docs well, and if they wanted to fix this with code changes, it would probably break other use cases. On the other hand, @aws-sdk/lib-storage could broaden its compatibility with everything without any breaking change. I am disappointed the team doesn't think this would be a worthwhile change. |
Thanks for your response. Totally understand the frustration that you're trying to help other users. However, since the type returned by Also I understand that there may be workaround to use PassThrough, from browsing the issues there on https://github.com/archiverjs/node-archiver/issues and hopefully it will get documented as you requested. Closing the issue for now. |
@aBurmeseDev I thought I would share some more context FWIW. I'm not assuming y'all don't know about things like this, but sharing it just in case you don't. Weird environmentsLast year I briefly worked at an SDK codegen company on supporting a wider variety of JavaScript environments -- Node, Deno, Bun, Vercel Edge, CloudFlare Workers, Jest node, Jest jsdom, react-native etc. We ended up being unable to support certain environments with function isBlob(x: any): x is Blob {
return x instanceof Object && typeof x.size === 'number' &&
typeof x.type === 'string' && typeof x.arrayBuffer === 'function' &&
typeof x.slice === 'function'
} Jest still has a particularly onerous problem with And as expected, Cross-realm compatibilitySome objects, for example For example, a Functions like
Has the AWS SDK team considered if you want the SDKs to generally be cross-realm compatible? If so, until the day that Unfortunately, userland code to test the identity of cross-realm objects can't prevent all false positives. But this is not necessarily so bad, because an object that happens to contain all of the expected properties of And even though the issue with |
@aBurmeseDev I just noticed that there's already duck typing support for Blob in the code... if (typeof (data as any).stream === "function") {
// approximate support for Blobs.
return getChunkStream<ReadableStream>((data as any).stream(), partSize, getDataReadableStream);
} |
converting this to feature request to prefer duck checks globally |
Checkboxes for prior research
Describe the bug
If I pass a polyfill for a
Readable
orReadableStream
inparams
inUpload
, the request fails sayingBody Data is unsupported format, expected data to be one of: string | Uint8Array | Buffer | Readable | ReadableStream | Blob
.This is very confusing when working with a library like
archiver
since it uses thereadable-stream
userland implementation of Node'sReadable
. Their docs don't make this clear at all (that's their bad), so I was baffled what was wrong until I dug into their code. And it would certainly be better ifarchiver
used Node's own streams when possible.But,
@aws-sdk
could tolerate cases like this instead of erroring out, and that would make things go more smoothly for users in a variety of cases.SDK version number
@aws-sdk/lib-storage 3.588.0
Which JavaScript Runtime is this issue in?
Node.js
Details of the browser/Node.js/ReactNative version
v20.10.0
Reproduction Steps
Observed Behavior
Running the code outputs the following error:
Expected Behavior
Upload would work if I had permission on this bucket
Possible Solution
Upload could use duck typing checks to determine if an object looks like a
Readable
orReadableStream
instead of usinginstanceof
checks.Additional Information/Context
I'm able to work around this by doing
archiver.pipe(new PassThrough())
since that returns a bonafide Node.jsReadable
instance.The text was updated successfully, but these errors were encountered: