V2EX henbf
 henbf 最近的时间轴更新
首先,我还是先来测试一下这个是个什么东西再说
2016-05-16 23:28:18 +08:00
henbf

henbf

  互联网
V2EX 第 171040 号会员,加入于 2016-04-28 15:55:54 +08:00
13 G 40 S 49 B
henbf 最近回复了
@zhouyin ,Node.js 不适合解析 csv ,Python 牛逼
@zhouyin 这中间还要看你对 csv 的每一行进行了怎么样的处理,你用 python 只是一读一写没有任何额外的处理,相当于复制。用 Node.js ,你却把每一行转换成数组,写的时候又把数组转换成字符串,当然慢了。

const { createReadStream, createWriteStream } = require("fs");

const inputPath = "../outpy.csv";
const outputPath = "./test.txt";


const readStream = createReadStream(inputPath, { highWaterMark: 256 * 1024 });
const writeStream = createWriteStream(outputPath, { flags: "a" });

readStream.pipe(writeStream);

readStream.on("end", () => {
console.log("finished");
writeStream.end();
});

readStream.on("error", (err) => {
console.error("Error reading file:", err);
});

writeStream.on("error", (err) => {
console.error("Error writing file:", err);
});
@zhouyin 你的写的不对

const { createReadStream, createWriteStream } = require("fs");
const { parse } = require("csv-parse");

const inputPath = "../outpy.csv";
const outputPath = "./test.txt";

const readStream = createReadStream(inputPath);
const writeStream = createWriteStream(outputPath, { flags: "a" });

const parser = parse({ delimiter: ",", from_line: 2 });

readStream.pipe(parser);

parser.on("data", (row) => {
writeStream.write(row.join(",") + "\n");
});

parser.on("end", () => {
console.log("finished");
writeStream.end();
});

parser.on("error", (error) => {
console.error("CSV Parsing Error:", error);
});
喷 Node.js 之前反思一下自己是不是应该先搞清楚 I/O 和流的基本概念
看注释,这网站 Cursor 生成的吧
流量 1500G ,带宽 10MB ,就算 24 小时满带宽使用,需要 14.2 天才能用完
关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     2540 人在线   最高记录 6679       Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 14ms UTC 04:25 PVG 12:25 LAX 20:25 JFK 23:25
Do have faith in what you're doing.
ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86