node-csv icon indicating copy to clipboard operation
node-csv copied to clipboard

One CSV to Another and strip 0x00 characters

Open 1Map opened this issue 2 years ago • 3 comments

I have a Pipe Delimited CSV (Source) like:

COLUMN 1|COLUMN 2|COLUMN 3
VALUE A1|VALUE A2|VALUE A3
VALUE B1|VALUE B2|VALUE B3

I want a CSV (Target) like:

"COLUMN 1","COLUMN 2","COLUMN 3"
"VALUE A1","VALUE A2","VALUE A3"
"VALUE B1","VALUE B2","VALUE B3"

How do I go about:

  1. Writing the source to a Target without going through "for loops" or "mapping" as it creates memory error on very large csv?
  2. Also in this process, remove all 0x00 (unprintable) characters ?

Will appreciate it if I can have a small sample on this.

1Map avatar Mar 17 '22 08:03 1Map

https://csv.js.org/parse/recipes/stream_pipe/ all the information for what's being asked is here. If you have 0x00 it sounds like you have UTF-16 you can try setting encoding https://csv.js.org/parse/options/encoding/

kitsunde avatar Jun 10 '22 04:06 kitsunde

@kitsunde Thanks,

Problem is that I do not know what format the CSV is in that the client upload (UTF-16, UTF-8, etc). This can be any of these.

1Map avatar Jun 10 '22 04:06 1Map

https://www.npmjs.com/search?q=charset-detection there's a lot of libraries that can help you detect encoding.

kitsunde avatar Jun 10 '22 04:06 kitsunde