Skip to content

Pass in a buffer rather than a file path #3

Closed

Description

@curiousdannii

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

Activity

  1. gignupg commented on Dec 20, 2021

    @gignupg
    Owner

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

  2. gfreecs0510 commented on Jan 12, 2023

    @gfreecs0510

    @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

  3. gignupg commented on Jan 13, 2023

    @gignupg
    Owner

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

  4. davuses commented on Mar 20, 2023

    @davuses

    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

  5. gignupg commented on Mar 24, 2023

    @gignupg
    Owner

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

  6. davuses commented on Mar 24, 2023

    @davuses

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

  7. gignupg commented on Mar 29, 2023

    @gignupg
    Owner

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

  8. erkstruwe commented on Jun 23, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions