Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使a流从一个管道流向另一个管道节点_Javascript_Node.js_Node Streams - Fatal编程技术网

Javascript 如何使a流从一个管道流向另一个管道节点

Javascript 如何使a流从一个管道流向另一个管道节点,javascript,node.js,node-streams,Javascript,Node.js,Node Streams,我只是试图理解节点流并尝试创建一个管道。因此,读取一个文件并写入另一个可写流,然后再次传递到res,因为这也是可写流{ //创建了读链 让file=fs.createReadStream('./temp_files/file1.txt')) //pipig this RES,因为is RES是另一个可写流 设des=fs.createWriteStream('./temp\u files/final.tct') 文件(DES)。管道(RES)/ /错误< P>不能链接两个可写流的管道调用。在中间

我只是试图理解节点流并尝试创建一个管道。因此,读取一个文件并写入另一个可写流,然后再次传递到res,因为这也是可写流<但是它抛出了错误

错误[错误流\u无法\u管道]:无法管道,不可读

请让我知道失败的原因,并看看下面的英特尔代码

const http = require('http')
const fs = require('fs')

var server = http.createServer((req, res)=>{
    //created the read strem
     let file = fs.createReadStream('./temp_files/file1.txt')
     // pipig this RES, since is RES is the aother writeable stream
     let des = fs.createWriteStream('./temp_files/final.tct')
     file.pipe(des).pipe(res) // ERROR <<<------------------------------

})

server.listen(9090, (req, res)=>{
    console.log("runnig at port 9090")
})
consthttp=require('http'))
常量fs=require('fs')
var server=http.createServer((req,res)=>{
//创建了读链
让file=fs.createReadStream('./temp_files/file1.txt'))
//pipig this RES,因为is RES是另一个可写流
设des=fs.createWriteStream('./temp\u files/final.tct')

文件(DES)。管道(RES)/ /错误< P>不能链接两个可写流的管道调用。在中间需要一个双工流。

因此,替换file.pipe(des).pipe(res)您可以尝试以下操作:

file.pipe(des);
文件管道(res)


由于DES不是一个转换流,它们可以独立工作,不应该有任何区别。

< P>不能用两个可写流链接管道调用。 因此,替换file.pipe(des).pipe(res)您可以尝试以下操作:

file.pipe(des);
文件管道(res)


由于des不是一个转换流,它们可以独立工作,不应该有任何区别。

可能需要将end:false传递到管道中,如下图所示,或者使用他们推荐的Appender模块可能需要将end:false传递到管道中,如下图所示,或者使用他们推荐的Appender模块