javascript 更改读取流块大小
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27641571/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Changing readstream chunksize
提问by Joe Thomas
I'm trying to create a socket based filetransfer system and because of that I came up with some trouble. I want to read files in chunks using node's fs.createReadStream() but I was unable to change the chunk size from 665536. I couldn't find anything about this.
我正在尝试创建一个基于套接字的文件传输系统,因此我遇到了一些麻烦。我想使用节点的 fs.createReadStream() 以块的形式读取文件,但我无法将块大小从 665536 更改。我找不到任何关于此的信息。
回答by mscdex
According to the ReadStream code, you should be able to increase the highWaterMark
by explicitly setting it in the ReadStream options:
根据ReadStream 代码,您应该能够highWaterMark
通过在 ReadStream 选项中显式设置来增加它:
var rs = fs.createReadStream('/foo/bar', { highWaterMark: 128 * 1024 });