有没有办法在 NodeJS 中重用管道转换链? [英] is there any way to reuse a chain of pipe transformations in NodeJS?

查看:29
本文介绍了有没有办法在 NodeJS 中重用管道转换链?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如如果我有

readableStream.pipe(ws1).pipe(ws2).pipe(ws3)

如何将转换链封装在单个函数中,然后在另一个转换链中重复使用?

How can I envelope that transformation chain in a single function and then reuse it in another transformation chain?

我想做这样的事情:

var transformationChain1 = readableStream.pipe(ws1).pipe(ws2).pipe(ws3)
readableStream2.pipe(transformationChain1).pipe(endWs)

推荐答案

你可能会用到

var combine = require('stream-combiner2')
var ws = combine(ws1, ws2, ws3);
readableStream2.pipe(ws).pipe(endWs);

这篇关于有没有办法在 NodeJS 中重用管道转换链?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆