Possible to use CsvParseStream in Node.js
Hi, is it possible to use nodejs file streams with deno's stdlib?
13 Replies
as far as I can tell there's nothing in
@std/path
or @std/fs
that opens a file
I'm sure loading to a string is possible, but the file is fairly bigThere is no function to open a file in any of the
@std
packages, because that's already included in Deno itself, see https://docs.deno.com/examples/streaming_files/yeah sorry I'm trying to use the libraries from node.js with jsr's node compatibility
I'm still interested if it's possible but for now I'm using npm's
csv-parse
Right, in that case it's likely that you're running into the issue that Node by default uses NodeStreams (older API) and
@std
is written for WebStreams. In Node you can convert between the two, see https://nodejs.org/api/webstreams.html#nodejs-streams-interoperabilityoooh that looks like it, thank you!
I'm looking into this again and got it working, but typescript is complaining about the types:
I'm not sure at the top off my head how to resolve that error, but you could also go with the Deno-native version when you're using Deno in the first place:
I am tempted to switch from node to deno, but last time (a month ago) I had a bunch of issues with the lsp in neovim...
Oh so the issue is that you're getting the type error with plain ts and not with Deno's LSP?
is there some tsconfig setting that would help?
need to check. Up until now I thought you were using Deno's LSP
Looks like the types in Node are a bit wonky. It infers the stream as
any
with .toWeb()
, so you need to manually override the type:
that still works, but this time the error has moved to the iteration
the type inference also vanished,
entry
used to be Record<string, string>
and now it's any
I'm afraid I can't help further. Sounds like Node's web stream types are pretty alpha
they're classified as "stable" haha
thank you for the help though, I'll look into moving my project to deno