Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing readstream chunksize

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.

like image 543
Joe Thomas Avatar asked Dec 24 '14 19:12

Joe Thomas


2 Answers

According to the ReadStream code, you should be able to increase the highWaterMark by explicitly setting it in the ReadStream options:

var rs = fs.createReadStream('/foo/bar', { highWaterMark: 128 * 1024 });
like image 53
mscdex Avatar answered Oct 18 '22 18:10

mscdex


This is how you are going to change the change the size of the chunk with highWaterMark : 8 , you can set it to 8,16,24 all are in bytes, be sure if you make chunk size to much high then you are by passing the benefit of using readerstream1. Because benefit of readerstream or stream is that they work efficiently while consuming less memory.

let readerstream1 = fs.createReadStream('shamoon.txt', { highWaterMark: 8 });
like image 2
Shamoon97 Avatar answered Oct 18 '22 17:10

Shamoon97