Skip to content
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

Don't modify the options object #27

Merged
merged 1 commit into from
Mar 16, 2019
Merged

Don't modify the options object #27

merged 1 commit into from
Mar 16, 2019

Conversation

wraugh
Copy link
Contributor

@wraugh wraugh commented Mar 16, 2019

I want to use split2 in pipelines where I can pass each transform the
same options object, e.g.

class MyTransform extends Transform {
    _transform (chunk, encoding, callback) {
    // ...
    }
}
var options = { highWaterMark: 1024 }
pump(split2(options), new MyTransform(options), process.stdout)

If split2 adds transform and flush properties to options, then
MyTransform will also set those options, and it won't behave as
expected.

To avoid this, we can use a shallow copy of options instead of
operating on the object directly.

I want to use split2 in pipelines where I can pass each transform the
same options object, e.g.

    class MyTransform extends Transform {
        _transform (chunk, encoding, callback) {
            // ...
        }
    }
    var options = { highWaterMark: 1024 }
    pump(split2(options), new MyTransform(options), process.stdout)

If split2 adds `transform` and `flush` properties to `options`, then
`MyTransform` will also set those options, and it won't behave as
expected.

To avoid this, we can use a shallow copy of `options` instead of
operating on the object directly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants