Skip to content
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

Closed
3 tasks done
adamwagman-customerinsightscdp opened this issue Nov 19, 2024 · 4 comments · Fixed by #691
Closed
3 tasks done

fileTypeFromBlob throws an exception on Mac #690

adamwagman-customerinsightscdp opened this issue Nov 19, 2024 · 4 comments · Fixed by #691
Assignees
Labels

Comments

@adamwagman-customerinsightscdp

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

  • I have searched the existing issues and could not find any related to my problem.

ESM (ECMAScript Module) Requirement Acknowledgment

  • My project is an ESM project and my package.json contains the following entry: "type": "module".

File-Type Scope Acknowledgment

  • I understand that file-type detects binary file types and not text or other formats.
@adamwagman-customerinsightscdp
Copy link
Author

Note that the MDN web docs confirm that ReadableStreamBYOBReader is not available on Safari and iOS.
browsercompat

https://developer.mozilla.org/en-US/docs/Web/API/ReadableStreamBYOBReader

@Borewit
Copy link
Collaborator

Borewit commented Nov 19, 2024

@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.

@Borewit Borewit self-assigned this Nov 19, 2024
@adamwagman-customerinsightscdp
Copy link
Author

@adamwagman-customerinsightscdp
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants