net: use decodeStrings public API for writable stream

Instead of using an undocumented underscore-prefixed property to
configure the writable stream instance to not encode strings as buffers,
use the public API which is an options property passed to the
constructor.

Refs: https://github.com/nodejs/node/issues/445

PR-URL: https://github.com/nodejs/node/pull/25201
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
Rich Trott 2018-12-23 21:59:19 -08:00 committed by Anna Henningsen
parent 86e2ec41af
commit 79aab5dd7c
No known key found for this signature in database
GPG Key ID: 9C63F3A6CD2AD8F9

View File

@ -255,6 +255,8 @@ function Socket(options) {
options.allowHalfOpen = true; options.allowHalfOpen = true;
// For backwards compat do not emit close on destroy. // For backwards compat do not emit close on destroy.
options.emitClose = false; options.emitClose = false;
// Handle strings directly.
options.decodeStrings = false;
stream.Duplex.call(this, options); stream.Duplex.call(this, options);
// Default to *not* allowing half open sockets. // Default to *not* allowing half open sockets.
@ -308,9 +310,6 @@ function Socket(options) {
this._pendingData = null; this._pendingData = null;
this._pendingEncoding = ''; this._pendingEncoding = '';
// handle strings directly
this._writableState.decodeStrings = false;
// If we have a handle, then start the flow of data into the // If we have a handle, then start the flow of data into the
// buffer. if not, then this will happen when we connect // buffer. if not, then this will happen when we connect
if (this._handle && options.readable !== false) { if (this._handle && options.readable !== false) {