Skip to content

Pass in a buffer rather than a file path #3

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
curiousdannii opened this issue Dec 20, 2021 · 8 comments
Closed

Pass in a buffer rather than a file path #3

curiousdannii opened this issue Dec 20, 2021 · 8 comments

Comments

@curiousdannii
Copy link

Would it be possible to pass in a buffer rather than a file path?

@gignupg
Copy link
Owner

gignupg commented Dec 20, 2021

Sure, we could add that option. I'll accept the pull request if you do one!

@gfreecs0510
Copy link

@gignupg seems like its a year old request, are you planning to support buffer/steam in the future? i tested ur work and i would say its more accurate than chardet package.

I'll try to create a PR myself if i find some time

@gignupg
Copy link
Owner

gignupg commented Jan 13, 2023

@gfreecs0510 That's a huge compliment, thanks a lot!
Regarding the buffer feature, I wasn't planning on implementing it myself, but I know that a lot of people have requested it, so a PR would be very welcome!

@davuses
Copy link

davuses commented Mar 20, 2023

You can create a blob object from the buffer and pass it as argument to the API, something like:

const file= new Blob([buffer]);
languageEncoding(file).then((fileInfo) => console.log(fileInfo));

This should work

@gignupg
Copy link
Owner

gignupg commented Mar 24, 2023

@davuses thx for the code snippet! Would you want to implement it and do a PR? I'm a little bit busy at the moment...

@davuses
Copy link

davuses commented Mar 24, 2023

@davuses thx for the code snippet! Would you want to implement it and do a PR? I'm a little bit busy at the moment...

It's probably not necessary to make changes to the code, like I said above the current API can handle buffer as long as you make a blob object out of it, it's quite simple. So maybe add a snippet demo to show how this could be done in readme file.

@gignupg
Copy link
Owner

gignupg commented Mar 29, 2023

Thx @davuses for clarifying! I added a link to your code snipped in the readme and published a new version to NPM!

@erkstruwe
Copy link
Contributor

You can create a blob object from the buffer and pass it as argument to the API, something like:

const file= new Blob([buffer]);
languageEncoding(file).then((fileInfo) => console.log(fileInfo));

This should work

This only works in the browser. I added a PR for support in Node.js: #12.

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

No branches or pull requests

5 participants