- Timestamp:
- 11/25/21 22:08:24 (3 years ago)
- Branches:
- master
- Children:
- 8d391a1
- Parents:
- 59329aa
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trip-planner-front/node_modules/ws/lib/permessage-deflate.js
r59329aa re29cc2e 1 1 'use strict'; 2 2 3 const Limiter = require('async-limiter'); 3 4 const zlib = require('zlib'); 4 5 5 6 const bufferUtil = require('./buffer-util'); 6 const Limiter = require('./limiter');7 7 const { kStatusCode, NOOP } = require('./constants'); 8 8 9 9 const TRAILER = Buffer.from([0x00, 0x00, 0xff, 0xff]); 10 const EMPTY_BLOCK = Buffer.from([0x00]); 11 10 12 const kPerMessageDeflate = Symbol('permessage-deflate'); 11 13 const kTotalLength = Symbol('total-length'); … … 30 32 * Creates a PerMessageDeflate instance. 31 33 * 32 * @param {Object} [options]Configuration options33 * @param {Boolean} [options.serverNoContextTakeover=false] Request/accept34 * disablingof server context takeover35 * @param {Boolean} [options.clientNoContextTakeover=false] Advertise/36 * acknowledgedisabling of client context takeover37 * @param {(Boolean|Number)} [options.serverMaxWindowBits]Request/confirm the34 * @param {Object} options Configuration options 35 * @param {Boolean} options.serverNoContextTakeover Request/accept disabling 36 * of server context takeover 37 * @param {Boolean} options.clientNoContextTakeover Advertise/acknowledge 38 * disabling of client context takeover 39 * @param {(Boolean|Number)} options.serverMaxWindowBits Request/confirm the 38 40 * use of a custom server window size 39 * @param {(Boolean|Number)} [options.clientMaxWindowBits]Advertise support41 * @param {(Boolean|Number)} options.clientMaxWindowBits Advertise support 40 42 * for, or request, a custom client window size 41 * @param {Object} [options.zlibDeflateOptions] Options to pass to zlib on 42 * deflate 43 * @param {Object} [options.zlibInflateOptions] Options to pass to zlib on 44 * inflate 45 * @param {Number} [options.threshold=1024] Size (in bytes) below which 46 * messages should not be compressed 47 * @param {Number} [options.concurrencyLimit=10] The number of concurrent 48 * calls to zlib 49 * @param {Boolean} [isServer=false] Create the instance in either server or 50 * client mode 51 * @param {Number} [maxPayload=0] The maximum allowed message length 43 * @param {Object} options.zlibDeflateOptions Options to pass to zlib on deflate 44 * @param {Object} options.zlibInflateOptions Options to pass to zlib on inflate 45 * @param {Number} options.threshold Size (in bytes) below which messages 46 * should not be compressed 47 * @param {Number} options.concurrencyLimit The number of concurrent calls to 48 * zlib 49 * @param {Boolean} isServer Create the instance in either server or client 50 * mode 51 * @param {Number} maxPayload The maximum allowed message length 52 52 */ 53 53 constructor(options, isServer, maxPayload) { … … 67 67 ? this._options.concurrencyLimit 68 68 : 10; 69 zlibLimiter = new Limiter( concurrency);69 zlibLimiter = new Limiter({ concurrency }); 70 70 } 71 71 } … … 134 134 135 135 if (this._deflate) { 136 const callback = this._deflate[kCallback];137 138 136 this._deflate.close(); 139 137 this._deflate = null; 140 141 if (callback) {142 callback(143 new Error(144 'The deflate stream was closed while data was being processed'145 )146 );147 }148 138 } 149 139 } … … 244 234 configurations.forEach((params) => { 245 235 Object.keys(params).forEach((key) => { 246 letvalue = params[key];236 var value = params[key]; 247 237 248 238 if (value.length > 1) { … … 295 285 296 286 /** 297 * Decompress data. Concurrency limited .287 * Decompress data. Concurrency limited by async-limiter. 298 288 * 299 289 * @param {Buffer} data Compressed data … … 303 293 */ 304 294 decompress(data, fin, callback) { 305 zlibLimiter. add((done) => {295 zlibLimiter.push((done) => { 306 296 this._decompress(data, fin, (err, result) => { 307 297 done(); … … 312 302 313 303 /** 314 * Compress data. Concurrency limited .304 * Compress data. Concurrency limited by async-limiter. 315 305 * 316 306 * @param {Buffer} data Data to compress … … 320 310 */ 321 311 compress(data, fin, callback) { 322 zlibLimiter. add((done) => {312 zlibLimiter.push((done) => { 323 313 this._compress(data, fin, (err, result) => { 324 314 done(); … … 346 336 : this.params[key]; 347 337 348 this._inflate = zlib.createInflateRaw({ 349 ...this._options.zlibInflateOptions, 350 windowBits 351 }); 338 this._inflate = zlib.createInflateRaw( 339 Object.assign({}, this._options.zlibInflateOptions, { windowBits }) 340 ); 352 341 this._inflate[kPerMessageDeflate] = this; 353 342 this._inflate[kTotalLength] = 0; … … 377 366 ); 378 367 379 if ( this._inflate._readableState.endEmitted) {368 if (fin && this.params[`${endpoint}_no_context_takeover`]) { 380 369 this._inflate.close(); 381 370 this._inflate = null; … … 383 372 this._inflate[kTotalLength] = 0; 384 373 this._inflate[kBuffers] = []; 385 386 if (fin && this.params[`${endpoint}_no_context_takeover`]) {387 this._inflate.reset();388 }389 374 } 390 375 … … 402 387 */ 403 388 _compress(data, fin, callback) { 389 if (!data || data.length === 0) { 390 process.nextTick(callback, null, EMPTY_BLOCK); 391 return; 392 } 393 404 394 const endpoint = this._isServer ? 'server' : 'client'; 405 395 … … 411 401 : this.params[key]; 412 402 413 this._deflate = zlib.createDeflateRaw({ 414 ...this._options.zlibDeflateOptions, 415 windowBits 416 }); 403 this._deflate = zlib.createDeflateRaw( 404 Object.assign({}, this._options.zlibDeflateOptions, { windowBits }) 405 ); 417 406 418 407 this._deflate[kTotalLength] = 0; … … 429 418 } 430 419 431 this._deflate[kCallback] = callback;432 433 420 this._deflate.write(data); 434 421 this._deflate.flush(zlib.Z_SYNC_FLUSH, () => { 435 422 if (!this._deflate) { 436 423 // 437 // The deflate stream was closed while data was being processed. 424 // This `if` statement is only needed for Node.js < 10.0.0 because as of 425 // commit https://github.com/nodejs/node/commit/5e3f5164, the flush 426 // callback is no longer called if the deflate stream is closed while 427 // data is being processed. 438 428 // 439 429 return; 440 430 } 441 431 442 letdata = bufferUtil.concat(432 var data = bufferUtil.concat( 443 433 this._deflate[kBuffers], 444 434 this._deflate[kTotalLength] … … 447 437 if (fin) data = data.slice(0, data.length - 4); 448 438 449 //450 // Ensure that the callback will not be called again in451 // `PerMessageDeflate#cleanup()`.452 //453 this._deflate[kCallback] = null;454 455 this._deflate[kTotalLength] = 0;456 this._deflate[kBuffers] = [];457 458 439 if (fin && this.params[`${endpoint}_no_context_takeover`]) { 459 this._deflate.reset(); 440 this._deflate.close(); 441 this._deflate = null; 442 } else { 443 this._deflate[kTotalLength] = 0; 444 this._deflate[kBuffers] = []; 460 445 } 461 446
Note:
See TracChangeset
for help on using the changeset viewer.