gpt4 book ai didi

javascript - 如何在 Deno 中将大量数据传递给 process.stdin.write?

转载 作者:行者123 更新时间:2023-12-04 07:23:27 28 4
gpt4 key购买 nike

将大量数据传递给 stdin 将失败。如果您在 unix 下运行此脚本,您将在终端中仅获得网站输出的一部分:

const cat = Deno.run({
cmd: ["cat"],
stdin: "piped"
});
await cat.stdin.write(new Uint8Array(
await (
await fetch("https://languagelog.ldc.upenn.edu/nll/?feed=atom")
).arrayBuffer()
));
cat.stdin.close();
await cat.status();
sample feed</feed> 结尾,但管道会在中间吞下:
Screen Shot 2021-07-13 at 00 22 38
有没有办法绕过这个问题,或者我是否发现了一个错误?

最佳答案

无外乎 Ryan Dahl himself answered me :

stdin.write is just one syscall, it returns the number of bytes written. If you use writeAll, I think it would work.

That said, ideally you'd stream large data, rather than buffer it up.

import { readerFromStreamReader } from "https://deno.land/std@0.100.0/io/streams.ts";

const cat = Deno.run({
cmd: ["cat"],
stdin: "piped",
});
const res = await fetch("https://languagelog.ldc.upenn.edu/nll/?feed=atom");
let r = readerFromStreamReader(res.body.getReader());
await Deno.copy(r, cat.stdin);
cat.stdin.close();
await cat.status();

关于javascript - 如何在 Deno 中将大量数据传递给 process.stdin.write?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68354462/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com