Node 什么时候发出数据事件? [英] When does Node emit a data event?

查看:22
本文介绍了Node 什么时候发出数据事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在考虑实现一个节点服务器,它将接收潜在大文件的上传并通过另一个流转发数据.我找到了这篇文章:

I'm looking at implementing a node server which will be receiving uploads of potentially large files and forwarding the data on through another stream. I've found this article:

http://www.componentix.com/blog/13/file-uploads-using-nodejs-once-again

其中有一些有用的代码示例,用于处理各种事件以及两侧不同速度的流的泵问题.我仍然不清楚(我似乎找不到文档)是什么时候按节点为传入流发出 'data' 事件.

Which has some useful code examples around handling the various events as well as the pump problem with different speeds of the streams on both sides. What's still not clear to me (and what I can't seem to find documentation for) is when exactly the 'data' event is emitted for the incoming stream by node.

节点文档状态:

事件:'数据'

接收数据时发出.参数 data 将是一个 Buffer 或细绳.数据的编码由 socket.setEncoding() 设置.(见可读流部分了解更多信息.)

Emitted when data is received. The argument data will be a Buffer or String. Encoding of data is set by socket.setEncoding(). (See the Readable Stream section for more information.)

接收数据时"是什么意思?当传入的数据块达到一定大小时会触发吗?传入连接何时关闭?过了一段时间?

What is meant by "when data is received"? Is this fired when the incoming data chunk reaches a certain size? When the incoming connection is closed? After a certain time?

推荐答案

流有一个内部缓冲区,用于存储数据,直到它准备好触发数据事件.这可能是几种情况,具体取决于流的类型:内部缓冲区已满、所有数据已读取、连接已关闭等.

The stream has an internal buffer that it uses to store the data until it's ready to fire the data event. That might be a few cases depending on the type of stream: internal buffer full, all data read, connection closed, etc.

网络流可能正在使用从套接字的 read 方法接收到的任何数据触发数据事件.如果能在节点源码中找到,我会参考.

The network stream is probably firing the data event with whatever data received from the socket's read method. If I can find it in the node source, I'll reference it.

这篇关于Node 什么时候发出数据事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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