Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2019-06-28 02:20:03 +0300
committerisaacs <i@izs.me>2019-06-30 06:23:54 +0300
commitf75d46a9ddfdc98f5050f1bfe853067a4e6c8ab9 (patch)
treed483a42200893a55e2ee19b282c477c0d4ef082b /node_modules/minizlib
parentec62362104be24458ad06d085be5d58ea61f5aeb (diff)
tar@4.4.10
Fixes a bug related to FSReqWrap on Node v12, and incorrect encoding/decoding of base-256 numeric values.
Diffstat (limited to 'node_modules/minizlib')
-rw-r--r--node_modules/minizlib/index.js159
-rw-r--r--node_modules/minizlib/package.json24
2 files changed, 77 insertions, 106 deletions
diff --git a/node_modules/minizlib/index.js b/node_modules/minizlib/index.js
index c91a59c92..df486965c 100644
--- a/node_modules/minizlib/index.js
+++ b/node_modules/minizlib/index.js
@@ -2,11 +2,13 @@
const assert = require('assert')
const Buffer = require('buffer').Buffer
-const binding = process.binding('zlib')
+const realZlib = require('zlib')
const constants = exports.constants = require('./constants.js')
const MiniPass = require('minipass')
+const OriginalBufferConcat = Buffer.concat
+
class ZlibError extends Error {
constructor (msg, errno) {
super('zlib: ' + msg)
@@ -54,24 +56,19 @@ const strategies = new Set([
// true or false if there is anything in the queue when
// you call the .write() method.
const _opts = Symbol('opts')
-const _chunkSize = Symbol('chunkSize')
const _flushFlag = Symbol('flushFlag')
const _finishFlush = Symbol('finishFlush')
const _handle = Symbol('handle')
-const _hadError = Symbol('hadError')
-const _buffer = Symbol('buffer')
-const _offset = Symbol('offset')
+const _onError = Symbol('onError')
const _level = Symbol('level')
const _strategy = Symbol('strategy')
const _ended = Symbol('ended')
-const _writeState = Symbol('writeState')
class Zlib extends MiniPass {
constructor (opts, mode) {
super(opts)
this[_ended] = false
this[_opts] = opts = opts || {}
- this[_chunkSize] = opts.chunkSize || constants.Z_DEFAULT_CHUNK
if (opts.flush && !validFlushFlags.has(opts.flush)) {
throw new TypeError('Invalid flush flag: ' + opts.flush)
}
@@ -119,18 +116,17 @@ class Zlib extends MiniPass {
}
}
- this[_handle] = new binding.Zlib(mode)
+ this[_handle] = new realZlib[mode](opts)
- this[_hadError] = false
- this[_handle].onerror = (message, errno) => {
+ this[_onError] = (err) => {
// there is no way to cleanly recover.
// continuing only obscures problems.
this.close()
- this[_hadError] = true
- const error = new ZlibError(message, errno)
+ const error = new ZlibError(err.message, err.errno)
this.emit('error', error)
}
+ this[_handle].on('error', this[_onError])
const level = typeof opts.level === 'number' ? opts.level
: constants.Z_DEFAULT_COMPRESSION
@@ -138,30 +134,9 @@ class Zlib extends MiniPass {
var strategy = typeof opts.strategy === 'number' ? opts.strategy
: constants.Z_DEFAULT_STRATEGY
- this[_writeState] = new Uint32Array(2);
- const window = opts.windowBits || constants.Z_DEFAULT_WINDOWBITS
- const memLevel = opts.memLevel || constants.Z_DEFAULT_MEMLEVEL
-
// API changed in node v9
/* istanbul ignore next */
- if (/^v[0-8]\./.test(process.version)) {
- this[_handle].init(window,
- level,
- memLevel,
- strategy,
- opts.dictionary)
- } else {
- this[_handle].init(window,
- level,
- memLevel,
- strategy,
- this[_writeState],
- () => {},
- opts.dictionary)
- }
- this[_buffer] = Buffer.allocUnsafe(this[_chunkSize])
- this[_offset] = 0
this[_level] = level
this[_strategy] = strategy
@@ -196,9 +171,18 @@ class Zlib extends MiniPass {
if (this[_level] !== level || this[_strategy] !== strategy) {
this.flush(constants.Z_SYNC_FLUSH)
assert(this[_handle], 'zlib binding closed')
+ // .params() calls .flush(), but the latter is always async in the
+ // core zlib. We override .flush() temporarily to intercept that and
+ // flush synchronously.
+ const origFlush = this[_handle].flush
+ this[_handle].flush = (flushFlag, cb) => {
+ this[_handle].flush = origFlush
+ this.flush(flushFlag)
+ cb()
+ }
this[_handle].params(level, strategy)
/* istanbul ignore else */
- if (!this[_hadError]) {
+ if (this[_handle]) {
this[_level] = level
this[_strategy] = strategy
}
@@ -244,64 +228,51 @@ class Zlib extends MiniPass {
if (typeof chunk === 'string')
chunk = Buffer.from(chunk, encoding)
- let availInBefore = chunk && chunk.length
- let availOutBefore = this[_chunkSize] - this[_offset]
- let inOff = 0 // the offset of the input buffer
- const flushFlag = this[_flushFlag]
- let writeReturn = true
-
assert(this[_handle], 'zlib binding closed')
- do {
- let res = this[_handle].writeSync(
- flushFlag,
- chunk, // in
- inOff, // in_off
- availInBefore, // in_len
- this[_buffer], // out
- this[_offset], //out_off
- availOutBefore // out_len
- )
-
- if (this[_hadError])
- break
-
- // API changed in v9
- /* istanbul ignore next */
- let availInAfter = res ? res[0] : this[_writeState][1]
- /* istanbul ignore next */
- let availOutAfter = res ? res[1] : this[_writeState][0]
-
- const have = availOutBefore - availOutAfter
- assert(have >= 0, 'have should not go down')
-
- if (have > 0) {
- const out = this[_buffer].slice(
- this[_offset], this[_offset] + have
- )
-
- this[_offset] += have
- // serve some output to the consumer.
- writeReturn = super.write(out) && writeReturn
- }
- // exhausted the output buffer, or used all the input create a new one.
- if (availOutAfter === 0 || this[_offset] >= this[_chunkSize]) {
- availOutBefore = this[_chunkSize]
- this[_offset] = 0
- this[_buffer] = Buffer.allocUnsafe(this[_chunkSize])
+ // _processChunk tries to .close() the native handle after it's done, so we
+ // intercept that by temporarily making it a no-op.
+ const nativeHandle = this[_handle]._handle
+ const originalNativeClose = nativeHandle.close
+ nativeHandle.close = () => {}
+ const originalClose = this[_handle].close
+ this[_handle].close = () => {}
+ // It also calls `Buffer.concat()` at the end, which may be convenient
+ // for some, but which we are not interested in as it slows us down.
+ Buffer.concat = (args) => args
+ let result
+ try {
+ result = this[_handle]._processChunk(chunk, this[_flushFlag])
+ } catch (err) {
+ this[_onError](err)
+ } finally {
+ Buffer.concat = OriginalBufferConcat
+ if (this[_handle]) {
+ // Core zlib resets `_handle` to null after attempting to close the
+ // native handle. Our no-op handler prevented actual closure, but we
+ // need to restore the `._handle` property.
+ this[_handle]._handle = nativeHandle
+ nativeHandle.close = originalNativeClose
+ this[_handle].close = originalClose
+ // `_processChunk()` adds an 'error' listener. If we don't remove it
+ // after each call, these handlers start piling up.
+ this[_handle].removeAllListeners('error')
}
+ }
- if (availOutAfter === 0) {
- // Not actually done. Need to reprocess.
- // Also, update the availInBefore to the availInAfter value,
- // so that if we have to hit it a third (fourth, etc.) time,
- // it'll have the correct byte counts.
- inOff += (availInBefore - availInAfter)
- availInBefore = availInAfter
- continue
+ let writeReturn
+ if (result) {
+ if (Array.isArray(result) && result.length > 0) {
+ // The first buffer is always `handle._outBuffer`, which would be
+ // re-used for later invocations; so, we always have to copy that one.
+ writeReturn = super.write(Buffer.from(result[0]))
+ for (let i = 1; i < result.length; i++) {
+ writeReturn = super.write(result[i])
+ }
+ } else {
+ writeReturn = super.write(Buffer.from(result))
}
- break
- } while (!this[_hadError])
+ }
if (cb)
cb()
@@ -312,46 +283,46 @@ class Zlib extends MiniPass {
// minimal 2-byte header
class Deflate extends Zlib {
constructor (opts) {
- super(opts, constants.DEFLATE)
+ super(opts, 'Deflate')
}
}
class Inflate extends Zlib {
constructor (opts) {
- super(opts, constants.INFLATE)
+ super(opts, 'Inflate')
}
}
// gzip - bigger header, same deflate compression
class Gzip extends Zlib {
constructor (opts) {
- super(opts, constants.GZIP)
+ super(opts, 'Gzip')
}
}
class Gunzip extends Zlib {
constructor (opts) {
- super(opts, constants.GUNZIP)
+ super(opts, 'Gunzip')
}
}
// raw - no header
class DeflateRaw extends Zlib {
constructor (opts) {
- super(opts, constants.DEFLATERAW)
+ super(opts, 'DeflateRaw')
}
}
class InflateRaw extends Zlib {
constructor (opts) {
- super(opts, constants.INFLATERAW)
+ super(opts, 'InflateRaw')
}
}
// auto-detect header.
class Unzip extends Zlib {
constructor (opts) {
- super(opts, constants.UNZIP)
+ super(opts, 'Unzip')
}
}
diff --git a/node_modules/minizlib/package.json b/node_modules/minizlib/package.json
index f3a57e9f1..0e6e4f467 100644
--- a/node_modules/minizlib/package.json
+++ b/node_modules/minizlib/package.json
@@ -1,27 +1,27 @@
{
- "_from": "minizlib@^1.1.1",
- "_id": "minizlib@1.1.1",
+ "_from": "minizlib@^1.2.1",
+ "_id": "minizlib@1.2.1",
"_inBundle": false,
- "_integrity": "sha512-TrfjCjk4jLhcJyGMYymBH6oTXcWjYbUAXTHDbtnWHjZC25h0cdajHuPE1zxb4DVmu8crfh+HwH/WMuyLG0nHBg==",
+ "_integrity": "sha512-7+4oTUOWKg7AuL3vloEWekXY2/D20cevzsrNT2kGWm+39J9hGTCBv8VI5Pm5lXZ/o3/mdR4f8rflAPhnQb8mPA==",
"_location": "/minizlib",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
- "raw": "minizlib@^1.1.1",
+ "raw": "minizlib@^1.2.1",
"name": "minizlib",
"escapedName": "minizlib",
- "rawSpec": "^1.1.1",
+ "rawSpec": "^1.2.1",
"saveSpec": null,
- "fetchSpec": "^1.1.1"
+ "fetchSpec": "^1.2.1"
},
"_requiredBy": [
"/tar"
],
- "_resolved": "https://registry.npmjs.org/minizlib/-/minizlib-1.1.1.tgz",
- "_shasum": "6734acc045a46e61d596a43bb9d9cd326e19cc42",
- "_spec": "minizlib@^1.1.1",
- "_where": "/Users/zkat/Documents/code/work/npm/node_modules/tar",
+ "_resolved": "https://registry.npmjs.org/minizlib/-/minizlib-1.2.1.tgz",
+ "_shasum": "dd27ea6136243c7c880684e8672bb3a45fd9b614",
+ "_spec": "minizlib@^1.2.1",
+ "_where": "/Users/isaacs/dev/npm/cli/node_modules/tar",
"author": {
"name": "Isaac Z. Schlueter",
"email": "i@izs.me",
@@ -37,7 +37,7 @@
"deprecated": false,
"description": "A small fast zlib stream built on [minipass](http://npm.im/minipass) and Node.js's zlib binding.",
"devDependencies": {
- "tap": "^10.7.2"
+ "tap": "^12.0.1"
},
"files": [
"index.js",
@@ -67,5 +67,5 @@
"preversion": "npm test",
"test": "tap test/*.js --100 -J"
},
- "version": "1.1.1"
+ "version": "1.2.1"
}