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

A nodejs example #5

Closed
wants to merge 1 commit into from
Closed

A nodejs example #5

wants to merge 1 commit into from

Conversation

hrgdavor
Copy link

It took me a while to find a way to use it in node. I would like others to have it available on main page in readme too :)

@CLAassistant
Copy link

CLAassistant commented Oct 26, 2024

CLA assistant check
All committers have signed the CLA.

Copy link
Member

@pimterry pimterry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @hrgdavor, thanks for the contribution! Definitely open to clarifying the readme around cases like that.

The change here doesn't look unreasonable, but I think the existing example should actually also work for Node - modern node now supports fetch and web streams too, so there shouldn't be a major issue there.

Can you explain more about how that didn't work for you? Or was it just that you wanted an FS example instead of a fetch example?

@hrgdavor
Copy link
Author

simply the example fetch throws error on node 20... also does not work in bun.

const compressedResponse = await fetch('somefile.xz');

// node throws: TypeError: Failed to parse URL from somefile.xz
// bun throws:  TypeError: fetch() URL is invalid

@pimterry
Copy link
Member

Ah yes - that's a placeholder, the assumption is that you'd use the URL of a xz file you'd like to download somewhere (not a local file). Good point though, that should be clearer.

It sounds like you're reading from disk then, not a file you're downloading from the web? I'd been assuming most xz content was file downloads, but of course it should work for any other use cases too.

If you're trying to read from disk, you probably want to start with Readable.toWeb(fs.createReadStream(filename)) which will give you a web file stream.

@pimterry
Copy link
Member

I've now expanded on this, and combined the explanation above with your example in the README here: 0cdec25

@pimterry pimterry closed this Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants