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
resolves #85 introduce onBeforeDataWrite callback #86
Conversation
@@ -84,6 +86,10 @@ module.exports = function factory (userOptions) { | |||
if (socket.writableEnded) { | |||
handleSocketWriteError(new Error('This socket has been ended by the other party'), data, encoding) | |||
} else { | |||
if (options.onBeforeDataWrite) { | |||
data = options.onBeforeDataWrite(data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this is bad practice here, but I've overwritten the existing data value to spare memory overhead from having to create another copy of the data.
If you're not into that, I can do something of the following:
let newData
if (options.onBeforeDataWrite) {
newData = options.onBeforeDataWrite(data)
}
socket.write(newData | data, ...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Addressed feedback.
|
why did you close this? |
I didn't. Looks like it auto-closes if I remove my forked repo. However, you should still be able to merge it? If you're unable to, I can re-fork and re-create the PR by creating a patch from this one and applying it. |
Odd, the Github app gives status saying it's mergable but the web UI completely removes it. Apologies, will re-fork and re-submit. |
I'm introducing a callback called
onBeforeDataWrite
with a signature(data: Buffer) => Buffer
that allows manipulation of the data before it is written out to the socket.This resolves #85.