-
-
Notifications
You must be signed in to change notification settings - Fork 373
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
fileTypeFromBlob throws an exception on Mac #690
Comments
Note that the MDN web docs confirm that ReadableStreamBYOBReader is not available on Safari and iOS. https://developer.mozilla.org/en-US/docs/Web/API/ReadableStreamBYOBReader |
@adamwagman-customerinsightscdp Thank you for raising this issue. The file-type module is fully compatible with Node.js ≥ 20; however, the fileTypeFromBlob function is not compatible in environments like Safari due to the lack of support for the ReadableStreamBYOBReader API. Please note that the behavior of Safari's JavaScript engine is independent of your Node.js installation. Installing or upgrading Node.js will not affect Safari's capabilities. To work around this limitation, you can use an alternative approach to read and process the Blob without relying on streaming. Here’s an example: import {fileTypeFromBuffer} from 'file-type';
async function readFromBlobWithoutStreaming(blob) {
const buffer = await blob.arrayBuffer();
return fileTypeFromBuffer(buffer);
} This approach converts the Blob into an ArrayBuffer and then determines the file type from the buffer, which should work seamlessly in Safari and other environments lacking BYOBReader support. |
Thanks! That is indeed the workaround I found. Might be worth adding to the docs. This came up in a website I created that works fine on PCs but not on a Mac. Took a while to track the app’s “Couldn’t upload image” down to this function. :)
…________________________________
From: Borewit ***@***.***>
Sent: Tuesday, November 19, 2024 1:35:09 PM
To: sindresorhus/file-type ***@***.***>
Cc: adamwagman-customerinsightscdp ***@***.***>; Mention ***@***.***>
Subject: Re: [sindresorhus/file-type] fileTypeFromBlob throws an exception on Mac (Issue #690)
@adamwagman-customerinsightscdp<https://github.com/adamwagman-customerinsightscdp> Thank you for raising this issue.
The file-type module is fully compatible with Node.js ≥ 20; however, the fileTypeFromBlob function is not compatible in environments like Safari due to the lack of support for the ReadableStreamBYOBReader<https://developer.mozilla.org/en-US/docs/Web/API/ReadableStreamBYOBReader> API.
Please note that the behavior of Safari's JavaScript engine is independent of your Node.js installation. Installing or upgrading Node.js will not affect Safari's capabilities.
To work around this limitation, you can use an alternative approach to read and process the Blob without relying on streaming. Here’s an example:
import {fileTypeFromBuffer} from 'file-type';
async function readFromBlobWithoutStreaming(blob) {
const buffer = await blob.arrayBuffer();
return fileTypeFromBuffer(buffer);
}
This approach converts the Blob into an ArrayBuffer and then determines the file type from the buffer, which should work seamlessly in Safari and other environments lacking BYOBReader support.
―
Reply to this email directly, view it on GitHub<#690 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/BCW4YEU5OWF5N5H7LK6MRET2BOAF3AVCNFSM6AAAAABSCLADVGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIOBWGQ3DEMBXGE>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Thank you!
…________________________________
From: Sindre Sorhus ***@***.***>
Sent: Wednesday, November 20, 2024 6:41:18 AM
To: sindresorhus/file-type ***@***.***>
Cc: adamwagman-customerinsightscdp ***@***.***>; Mention ***@***.***>
Subject: Re: [sindresorhus/file-type] fileTypeFromBlob throws an exception on Mac (Issue #690)
Closed #690<#690> as completed via #691<#691>.
—
Reply to this email directly, view it on GitHub<#690 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/BCW4YEUO4JYYT5HKABJMB4D2BRYN5AVCNFSM6AAAAABSCLADVGVHI2DSMVQWIX3LMV45UABCJFZXG5LFIV3GK3TUJZXXI2LGNFRWC5DJN5XDWMJVGM3DKOJSGU2DEMQ>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Description
On a Mac, fileTypeFromBlob throws an exception that ReadableStreamBYOBReader is not available, even though the version of Node on the Mac is v20.12.0.
The file-type package docs claim that any version >= 20 should work: "It will stream the underlying Blob, and required a ReadableStreamBYOBReader which require Node.js ≥ 20."
Existing Issue Check
ESM (ECMAScript Module) Requirement Acknowledgment
package.json
contains the following entry:"type": "module"
.File-Type Scope Acknowledgment
The text was updated successfully, but these errors were encountered: