Skip to content

Commit

Permalink
feat(csv-issues-esm): issue 423
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed May 13, 2024
1 parent 7ca18b2 commit c255eb5
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
45 changes: 45 additions & 0 deletions demo/issues-esm/lib/423.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
'skip test'

import fs from "node:fs";
import os from "node:os";
import dedent from "dedent";
import { Writable } from "node:stream";
// import { Readable } from "node:stream";
import { pipeline } from "node:stream/promises";
import { parse } from "csv-parse";
import { stringify } from "csv-stringify";
import { exec as _exec } from "node:child_process";
import util from "node:util";
const exec = util.promisify(_exec);

const dir = os.tmpdir()

const {stdout, stderr} = await exec(dedent`
[ -f ${dir}/csv-423/allCountries.txt ] && exit 0
mkdir -p ${dir}/csv-423
cd ${dir}/csv-423
curl https://download.geonames.org/export/dump/allCountries.zip -O
unzip allCountries.zip
ls -l
`)

await pipeline(
fs.createReadStream(`${dir}/csv-423/allCountries.txt`),
parse({
bom: true,
cast: true,
columns: false,
comment: "#",
comment_no_infix: true,
delimiter: "\t",
escape: null,
groupColumnsByName: false,
quote: null,
record_delimiter: ["\n", "\r", "\r\n"],
relax_quotes: true,
skip_empty_lines: true,
}),
stringify({ delimiter: "|" }),
// process.stdout
new Writable ({write: (chunk, encoding, callback) => callback()})
);
1 change: 1 addition & 0 deletions demo/issues-esm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"csv-generate": "^4.4.0",
"csv-parse": "^5.5.5",
"csv-stringify": "^6.4.6",
"dedent": "^1.5.3",
"desm": "^1.3.0"
}
}

0 comments on commit c255eb5

Please sign in to comment.