string_decoder: lazy loaded
PR-URL: https://github.com/nodejs/node/pull/20567 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
This commit is contained in:
parent
11892b0b64
commit
f4f8b22f7d
@ -40,7 +40,9 @@ const {
|
|||||||
} = require('internal/errors').codes;
|
} = require('internal/errors').codes;
|
||||||
const ReadableAsyncIterator = require('internal/streams/async_iterator');
|
const ReadableAsyncIterator = require('internal/streams/async_iterator');
|
||||||
const { emitExperimentalWarning } = require('internal/util');
|
const { emitExperimentalWarning } = require('internal/util');
|
||||||
var StringDecoder;
|
|
||||||
|
// Lazy loaded to improve the startup performance.
|
||||||
|
let StringDecoder;
|
||||||
|
|
||||||
util.inherits(Readable, Stream);
|
util.inherits(Readable, Stream);
|
||||||
|
|
||||||
|
@ -14,7 +14,6 @@ const {
|
|||||||
ERR_MISSING_ARGS
|
ERR_MISSING_ARGS
|
||||||
}
|
}
|
||||||
} = require('internal/errors');
|
} = require('internal/errors');
|
||||||
const { StringDecoder } = require('string_decoder');
|
|
||||||
const EventEmitter = require('events');
|
const EventEmitter = require('events');
|
||||||
const net = require('net');
|
const net = require('net');
|
||||||
const dgram = require('dgram');
|
const dgram = require('dgram');
|
||||||
@ -47,6 +46,9 @@ const {
|
|||||||
|
|
||||||
const { SocketListSend, SocketListReceive } = SocketList;
|
const { SocketListSend, SocketListReceive } = SocketList;
|
||||||
|
|
||||||
|
// Lazy loaded for startup performance.
|
||||||
|
let StringDecoder;
|
||||||
|
|
||||||
const MAX_HANDLE_RETRANSMISSIONS = 3;
|
const MAX_HANDLE_RETRANSMISSIONS = 3;
|
||||||
|
|
||||||
// this object contain function to convert TCP objects to native handle objects
|
// this object contain function to convert TCP objects to native handle objects
|
||||||
@ -476,6 +478,8 @@ function setupChannel(target, channel) {
|
|||||||
|
|
||||||
const control = new Control(channel);
|
const control = new Control(channel);
|
||||||
|
|
||||||
|
if (StringDecoder === undefined)
|
||||||
|
StringDecoder = require('string_decoder').StringDecoder;
|
||||||
var decoder = new StringDecoder('utf8');
|
var decoder = new StringDecoder('utf8');
|
||||||
var jsonBuffer = '';
|
var jsonBuffer = '';
|
||||||
var pendingHandle = null;
|
var pendingHandle = null;
|
||||||
|
@ -28,11 +28,13 @@ const {
|
|||||||
|
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const LazyTransform = require('internal/streams/lazy_transform');
|
const LazyTransform = require('internal/streams/lazy_transform');
|
||||||
const { StringDecoder } = require('string_decoder');
|
|
||||||
|
|
||||||
const { inherits } = require('util');
|
const { inherits } = require('util');
|
||||||
const { normalizeEncoding } = require('internal/util');
|
const { normalizeEncoding } = require('internal/util');
|
||||||
|
|
||||||
|
// Lazy loaded for startup performance.
|
||||||
|
let StringDecoder;
|
||||||
|
|
||||||
function rsaFunctionFor(method, defaultPadding) {
|
function rsaFunctionFor(method, defaultPadding) {
|
||||||
return function(options, buffer) {
|
return function(options, buffer) {
|
||||||
const key = options.key || options;
|
const key = options.key || options;
|
||||||
@ -49,6 +51,8 @@ const privateDecrypt = rsaFunctionFor(_privateDecrypt, RSA_PKCS1_OAEP_PADDING);
|
|||||||
|
|
||||||
function getDecoder(decoder, encoding) {
|
function getDecoder(decoder, encoding) {
|
||||||
encoding = normalizeEncoding(encoding);
|
encoding = normalizeEncoding(encoding);
|
||||||
|
if (StringDecoder === undefined)
|
||||||
|
StringDecoder = require('string_decoder').StringDecoder;
|
||||||
decoder = decoder || new StringDecoder(encoding);
|
decoder = decoder || new StringDecoder(encoding);
|
||||||
assert(decoder.encoding === encoding, 'Cannot change encoding');
|
assert(decoder.encoding === encoding, 'Cannot change encoding');
|
||||||
return decoder;
|
return decoder;
|
||||||
|
@ -35,7 +35,6 @@ const {
|
|||||||
const { debug, inherits } = require('util');
|
const { debug, inherits } = require('util');
|
||||||
const { Buffer } = require('buffer');
|
const { Buffer } = require('buffer');
|
||||||
const EventEmitter = require('events');
|
const EventEmitter = require('events');
|
||||||
const { StringDecoder } = require('string_decoder');
|
|
||||||
const {
|
const {
|
||||||
CSI,
|
CSI,
|
||||||
emitKeys,
|
emitKeys,
|
||||||
@ -52,6 +51,9 @@ const {
|
|||||||
kClearScreenDown
|
kClearScreenDown
|
||||||
} = CSI;
|
} = CSI;
|
||||||
|
|
||||||
|
// Lazy load StringDecoder for startup performance.
|
||||||
|
let StringDecoder;
|
||||||
|
|
||||||
const kHistorySize = 30;
|
const kHistorySize = 30;
|
||||||
const kMincrlfDelay = 100;
|
const kMincrlfDelay = 100;
|
||||||
// \r\n, \n, or \r followed by something other than \n
|
// \r\n, \n, or \r followed by something other than \n
|
||||||
@ -73,6 +75,9 @@ function Interface(input, output, completer, terminal) {
|
|||||||
return new Interface(input, output, completer, terminal);
|
return new Interface(input, output, completer, terminal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (StringDecoder === undefined)
|
||||||
|
StringDecoder = require('string_decoder').StringDecoder;
|
||||||
|
|
||||||
this._sawReturnAt = 0;
|
this._sawReturnAt = 0;
|
||||||
this.isCompletionEnabled = true;
|
this.isCompletionEnabled = true;
|
||||||
this._sawKeyPress = false;
|
this._sawKeyPress = false;
|
||||||
@ -987,6 +992,9 @@ Interface.prototype._ttyWrite = function(s, key) {
|
|||||||
|
|
||||||
function emitKeypressEvents(stream, iface) {
|
function emitKeypressEvents(stream, iface) {
|
||||||
if (stream[KEYPRESS_DECODER]) return;
|
if (stream[KEYPRESS_DECODER]) return;
|
||||||
|
|
||||||
|
if (StringDecoder === undefined)
|
||||||
|
StringDecoder = require('string_decoder').StringDecoder;
|
||||||
stream[KEYPRESS_DECODER] = new StringDecoder('utf8');
|
stream[KEYPRESS_DECODER] = new StringDecoder('utf8');
|
||||||
|
|
||||||
stream[ESCAPE_DECODER] = emitKeys(stream);
|
stream[ESCAPE_DECODER] = emitKeys(stream);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user