-
-
Notifications
You must be signed in to change notification settings - Fork 354
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
Consider alternate (browser friendly) buffer #578
Comments
Ideally, all code should be using If anyone wants to work on this, the first task would be to convert the dependencies of |
That work has started to some extend Borewit/token-types#246, but yet there is much more work to do. |
+1 |
That function already exist @volarname : |
Yes, but it doesn't work in modern frameworks like SvelteKit as example. It uses vite under the hood and shows the warnings:
|
This module has been primary written for Node.js. It does depend on Buffer. There is browser friendly buffer module available, but you depend on your framework how easy that is to fit it in. |
Interesting!, very nice guidance. I will give it try (starting with the dependent modules first). |
It is not only graph TD;
FT-->S
FT(file-type)-->RWNS(readable-web-to-node-stream)
S(strtok3)-->P(peek-readable)
S(strtok3)-->TO("@tokenizer/token")
TY(token-types)-->TO
TY-->IE("ieee754")
FT-->TY
TY-->NB(node:buffer)
RWNS-->RS(readable-stream)
RS-->SD(string_decoder)
SD-->SB(safe-buffer)
RS-->UD(util-deprecate)
RS-->I(inherits)
style NB fill:#F88,stroke:#A44
style SB fill:#F88,stroke:#A44
style SD fill:#CCC,stroke:#888
style IE fill:#CCC,stroke:#888
style UD fill:#CCC,stroke:#888
style I fill:#CCC,stroke:#888
|
I still don't see a good alternative for the string encoding node:buffer supports: e.g.: Buffer.from(uint8Array).toString(encoding); |
I think this library can help? https://github.com/sindresorhus/uint8array-extras I can see there are methods to |
i've got a working browser-consumable fork at https://github.com/sgtpooki/file-type, but stream and file support has been disabled for now (since I don't need it for my use-case). All tests for fileTypeFromBuffer are passing. |
Hi 👋 Facing similar issues after upgrading from a very old fork of this lib. So just to be crystal clear - this lib can't be used without polyfiling |
Encountering this while playing with Cloudflare workers, would be nice for |
Fix toeverything/AFFiNE#6603 This pull request switches the [file-type](https://github.com/sindresorhus/file-type) to [@sgtpooki/file-type](https://github.com/sgtpooki/file-type). It also includes other minor changes and updates. ~~The `file-type` is no longer useful since the toeverything/AFFiNE#3245 resolved in toeverything/AFFiNE#5565 --- More context see toeverything/AFFiNE#3245 #3555 #4818 #5372 sindresorhus/file-type#578 --- ## Caveat The [@sgtpooki/file-type](https://github.com/sgtpooki/file-type) is an unofficial fork package from the community. It may need to be source code audited before updating. Also, thanks to sgtpooki for their strong contribution to @sgtpooki/file-type
You can use this dependency vite-plugin-node-polyfills to solve the loading problem of Install the package as a dev dependency. # npm
npm install --save-dev vite-plugin-node-polyfills
# pnpm
pnpm install --save-dev vite-plugin-node-polyfills
# yarn
yarn add --dev vite-plugin-node-polyfills Add the plugin to your vite.config.ts file. import { defineConfig } from 'vite'
import { nodePolyfills } from 'vite-plugin-node-polyfills'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
nodePolyfills(),
],
}) |
This pull request is for sunsetting the `@sgtpooki/file-type` and using the official file-type v19.1.0. The `file-type` package has replaced the usage of `node:buffer` with `Uint8Array`. This change allows it to run safely in the browser now. The file-type package is used in the attachment-block and image-block modules to determine the file type of uploaded files. Related to #6803 sindresorhus/file-type#578 (comment)
The official `file-type` package has replaced the usage of node:buffer with Uint8Array. This change allows it to run safely in the browser now. Related to sindresorhus/file-type#578
Hello! :-) I'd love to be able to use this module in my SvelteKit app, but node:buffer dep is not something I've been able to workaround via Vite polyfill (same issue for other frameworks like Nextjs as well).
Have or can you consider alt buffer impl that is browser friendly? Or, any tips on configuring for use in SvelteKit, Vue, Nextjs, etc?
Thanks!
The text was updated successfully, but these errors were encountered: