Ignore:
Timestamp:
11/25/21 22:08:24 (3 years ago)
Author:
Ema <ema_spirova@…>
Branches:
master
Children:
8d391a1
Parents:
59329aa
Message:

primeNG components

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trip-planner-front/node_modules/ws/lib/permessage-deflate.js

    r59329aa re29cc2e  
    11'use strict';
    22
     3const Limiter = require('async-limiter');
    34const zlib = require('zlib');
    45
    56const bufferUtil = require('./buffer-util');
    6 const Limiter = require('./limiter');
    77const { kStatusCode, NOOP } = require('./constants');
    88
    99const TRAILER = Buffer.from([0x00, 0x00, 0xff, 0xff]);
     10const EMPTY_BLOCK = Buffer.from([0x00]);
     11
    1012const kPerMessageDeflate = Symbol('permessage-deflate');
    1113const kTotalLength = Symbol('total-length');
     
    3032   * Creates a PerMessageDeflate instance.
    3133   *
    32    * @param {Object} [options] Configuration options
    33    * @param {Boolean} [options.serverNoContextTakeover=false] Request/accept
    34    *     disabling of server context takeover
    35    * @param {Boolean} [options.clientNoContextTakeover=false] Advertise/
    36    *     acknowledge disabling of client context takeover
    37    * @param {(Boolean|Number)} [options.serverMaxWindowBits] Request/confirm the
     34   * @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
    3840   *     use of a custom server window size
    39    * @param {(Boolean|Number)} [options.clientMaxWindowBits] Advertise support
     41   * @param {(Boolean|Number)} options.clientMaxWindowBits Advertise support
    4042   *     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
    5252   */
    5353  constructor(options, isServer, maxPayload) {
     
    6767          ? this._options.concurrencyLimit
    6868          : 10;
    69       zlibLimiter = new Limiter(concurrency);
     69      zlibLimiter = new Limiter({ concurrency });
    7070    }
    7171  }
     
    134134
    135135    if (this._deflate) {
    136       const callback = this._deflate[kCallback];
    137 
    138136      this._deflate.close();
    139137      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       }
    148138    }
    149139  }
     
    244234    configurations.forEach((params) => {
    245235      Object.keys(params).forEach((key) => {
    246         let value = params[key];
     236        var value = params[key];
    247237
    248238        if (value.length > 1) {
     
    295285
    296286  /**
    297    * Decompress data. Concurrency limited.
     287   * Decompress data. Concurrency limited by async-limiter.
    298288   *
    299289   * @param {Buffer} data Compressed data
     
    303293   */
    304294  decompress(data, fin, callback) {
    305     zlibLimiter.add((done) => {
     295    zlibLimiter.push((done) => {
    306296      this._decompress(data, fin, (err, result) => {
    307297        done();
     
    312302
    313303  /**
    314    * Compress data. Concurrency limited.
     304   * Compress data. Concurrency limited by async-limiter.
    315305   *
    316306   * @param {Buffer} data Data to compress
     
    320310   */
    321311  compress(data, fin, callback) {
    322     zlibLimiter.add((done) => {
     312    zlibLimiter.push((done) => {
    323313      this._compress(data, fin, (err, result) => {
    324314        done();
     
    346336          : this.params[key];
    347337
    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      );
    352341      this._inflate[kPerMessageDeflate] = this;
    353342      this._inflate[kTotalLength] = 0;
     
    377366      );
    378367
    379       if (this._inflate._readableState.endEmitted) {
     368      if (fin && this.params[`${endpoint}_no_context_takeover`]) {
    380369        this._inflate.close();
    381370        this._inflate = null;
     
    383372        this._inflate[kTotalLength] = 0;
    384373        this._inflate[kBuffers] = [];
    385 
    386         if (fin && this.params[`${endpoint}_no_context_takeover`]) {
    387           this._inflate.reset();
    388         }
    389374      }
    390375
     
    402387   */
    403388  _compress(data, fin, callback) {
     389    if (!data || data.length === 0) {
     390      process.nextTick(callback, null, EMPTY_BLOCK);
     391      return;
     392    }
     393
    404394    const endpoint = this._isServer ? 'server' : 'client';
    405395
     
    411401          : this.params[key];
    412402
    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      );
    417406
    418407      this._deflate[kTotalLength] = 0;
     
    429418    }
    430419
    431     this._deflate[kCallback] = callback;
    432 
    433420    this._deflate.write(data);
    434421    this._deflate.flush(zlib.Z_SYNC_FLUSH, () => {
    435422      if (!this._deflate) {
    436423        //
    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.
    438428        //
    439429        return;
    440430      }
    441431
    442       let data = bufferUtil.concat(
     432      var data = bufferUtil.concat(
    443433        this._deflate[kBuffers],
    444434        this._deflate[kTotalLength]
     
    447437      if (fin) data = data.slice(0, data.length - 4);
    448438
    449       //
    450       // Ensure that the callback will not be called again in
    451       // `PerMessageDeflate#cleanup()`.
    452       //
    453       this._deflate[kCallback] = null;
    454 
    455       this._deflate[kTotalLength] = 0;
    456       this._deflate[kBuffers] = [];
    457 
    458439      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] = [];
    460445      }
    461446
Note: See TracChangeset for help on using the changeset viewer.