Node.js中面向行的流 [英] Line-oriented streams in Node.js

查看:133
本文介绍了Node.js中面向行的流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Node.js开发一个多进程应用程序。在此应用程序中,父进程将生成子进程并使用基于JSON的消息传递协议通过管道与其进行通信。我发现大型JSON消息可能会被切断,因此发送到管道上的数据侦听器的单个块不包含完整的JSON消息。此外,小JSON消息可以分组在同一块中。每个JSON消息将由换行符分隔,因此我想知道是否已有一个实用程序将缓冲管道读取流,以便它一次发出一行(因此,对于我的应用程序,一个JSON文档在一个时间)。这似乎是一个非常常见的用例,所以我想知道它是否已经完成。

I'm developing a multi-process application using Node.js. In this application, a parent process will spawn a child process and communicate with it using a JSON-based messaging protocol over a pipe. I've found that large JSON messages may get "cut off", such that a single "chunk" emitted to the data listener on the pipe does not contain the full JSON message. Furthermore, small JSON messages may be grouped in the same chunk. Each JSON message will be delimited by a newline character, and so I'm wondering if there is already a utility that will buffer the pipe read stream such that it emits one line at a time (and hence, for my application, one JSON document at a time). This seems like it would be a pretty common use case, so I'm wondering if it has already been done.

我很感激任何人都能提供的指导。谢谢。

I'd appreciate any guidance anyone can offer. Thanks.

推荐答案

也许佩德罗的运营商可以帮助您吗?

Maybe Pedro's carrier can help you?


运营商可以帮助您通过node.js实施新的
终止协议。

Carrier helps you implement new-line terminated protocols over node.js.

客户可以向您发送
行的行数,运营商只会在每条已完成的行上通知您

The client can send you chunks of lines and carrier will only notify you on each completed line.

这篇关于Node.js中面向行的流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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