-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ability to set highWaterMark on transform stream? #8855
Comments
All of the constructors can already accept options, including var Transform = require('stream').Transform;
var inherits = require('util').inherits;
function MyTransform(opts) {
if (typeof opts !== 'object' || opts === null)
opts = {};
Transform.call(this, { highWaterMark: opts.highWaterMark });
// Or just: `Transform.call(this, opts);`
// Other initialization ...
}
inherits(MyTransform, Transform);
MyTransform.prototype._transform = function(chunk, enc, cb) {
// ...
}; |
Ok, thanks. Maybe I'm misunderstanding something then. I just tested the following code, which outputs var Transform = require('stream').Transform
var RandomStream = require('common-streams').RandomStream
class CustomTransform extends Transform {
constructor() {
super({
highWaterMark: 100,
})
}
_transform(chunk, enc, cb) {
console.log(chunk.length)
cb(null, chunk)
}
}
const rand = new RandomStream(10 * 1024 * 1024)
rand.pipe(new CustomTransform()) Is |
|
Ah ok, so it's more of a signal to upstream but not enforced, thanks. |
You should set it on the read stream you want to connect to your transform stream, otherwise it is not applied. I got sometimes bigger chunks even when I set it, so you cannot rely on this. I expect in my code that the chunk size is totally random and wait for more chunks if it is too small. |
How can I set the chunk size in |
If you're here because your Readable.toWeb(stream) then try changing it to: Readable.from(stream) Which fixes the problem for me. |
I noticed that transform streams buffer up to 16kb (the default high watermark for read/write streams) even when they are not piping anywhere. I looked through the code/docs and it seems this value can't be set by implementers. As I'm writing a library which relies on this behaviour (transform buffering even when not piping to anywhere), I'd like to make sure it's not going to change and also was wondering if it would be possible for the Transform constructor to accept the
highWaterMark
option as well.The text was updated successfully, but these errors were encountered: