diff options
author | isaacs <i@izs.me> | 2020-07-24 22:55:18 +0300 |
---|---|---|
committer | isaacs <i@izs.me> | 2020-07-29 21:55:03 +0300 |
commit | 53ed7e5205a3f4d5d33828ff9dc11c093f482f7b (patch) | |
tree | d76317be79432c9527e8fb37d4c13e0719cdbaf9 /node_modules/fs-minipass | |
parent | bbe4279120c94791b70d97f235c73d972fd67354 (diff) |
reset deps using npm v7
First self-install!
Diffstat (limited to 'node_modules/fs-minipass')
-rw-r--r-- | node_modules/fs-minipass/index.js | 103 | ||||
-rw-r--r-- | node_modules/fs-minipass/package.json | 66 |
2 files changed, 89 insertions, 80 deletions
diff --git a/node_modules/fs-minipass/index.js b/node_modules/fs-minipass/index.js index cd585a83c..9b0779c80 100644 --- a/node_modules/fs-minipass/index.js +++ b/node_modules/fs-minipass/index.js @@ -3,11 +3,21 @@ const MiniPass = require('minipass') const EE = require('events').EventEmitter const fs = require('fs') -// for writev -const binding = process.binding('fs') -const writeBuffers = binding.writeBuffers +let writev = fs.writev /* istanbul ignore next */ -const FSReqWrap = binding.FSReqWrap || binding.FSReqCallback +if (!writev) { + // This entire block can be removed if support for earlier than Node.js + // 12.9.0 is not needed. + const binding = process.binding('fs') + const FSReqWrap = binding.FSReqWrap || binding.FSReqCallback + + writev = (fd, iovec, pos, cb) => { + const done = (er, bw) => cb(er, bw, iovec) + const req = new FSReqWrap() + req.oncomplete = done + binding.writeBuffers(fd, iovec, pos, req) + } +} const _autoClose = Symbol('_autoClose') const _close = Symbol('_close') @@ -36,17 +46,20 @@ const _size = Symbol('_size') const _write = Symbol('_write') const _writing = Symbol('_writing') const _defaultFlag = Symbol('_defaultFlag') +const _errored = Symbol('_errored') class ReadStream extends MiniPass { constructor (path, opt) { opt = opt || {} super(opt) + this.readable = true this.writable = false if (typeof path !== 'string') throw new TypeError('path must be a string') + this[_errored] = false this[_fd] = typeof opt.fd === 'number' ? opt.fd : null this[_path] = path this[_readSize] = opt.readSize || 16*1024*1024 @@ -96,7 +109,8 @@ class ReadStream extends MiniPass { this[_reading] = true const buf = this[_makeBuf]() /* istanbul ignore if */ - if (buf.length === 0) return process.nextTick(() => this[_onread](null, 0, buf)) + if (buf.length === 0) + return process.nextTick(() => this[_onread](null, 0, buf)) fs.read(this[_fd], buf, 0, buf.length, null, (er, br, buf) => this[_onread](er, br, buf)) } @@ -112,8 +126,9 @@ class ReadStream extends MiniPass { [_close] () { if (this[_autoClose] && typeof this[_fd] === 'number') { - fs.close(this[_fd], _ => this.emit('close')) + const fd = this[_fd] this[_fd] = null + fs.close(fd, er => er ? this.emit('error', er) : this.emit('close')) } } @@ -150,6 +165,12 @@ class ReadStream extends MiniPass { this[_read]() break + case 'error': + if (this[_errored]) + return + this[_errored] = true + return super.emit(ev, data) + default: return super.emit(ev, data) } @@ -176,7 +197,8 @@ class ReadStreamSync extends ReadStream { do { const buf = this[_makeBuf]() /* istanbul ignore next */ - const br = buf.length === 0 ? 0 : fs.readSync(this[_fd], buf, 0, buf.length, null) + const br = buf.length === 0 ? 0 + : fs.readSync(this[_fd], buf, 0, buf.length, null) if (!this[_handleChunk](br, buf)) break } while (true) @@ -191,10 +213,9 @@ class ReadStreamSync extends ReadStream { [_close] () { if (this[_autoClose] && typeof this[_fd] === 'number') { - try { - fs.closeSync(this[_fd]) - } catch (er) {} + const fd = this[_fd] this[_fd] = null + fs.closeSync(fd) this.emit('close') } } @@ -205,6 +226,8 @@ class WriteStream extends EE { opt = opt || {} super(opt) this.readable = false + this.writable = true + this[_errored] = false this[_writing] = false this[_ended] = false this[_needDrain] = false @@ -225,6 +248,16 @@ class WriteStream extends EE { this[_open]() } + emit (ev, data) { + if (ev === 'error') { + if (this[_errored]) + return + this[_errored] = true + } + return super.emit(ev, data) + } + + get fd () { return this[_fd] } get path () { return this[_path] } @@ -264,11 +297,12 @@ class WriteStream extends EE { if (!this[_writing] && !this[_queue].length && typeof this[_fd] === 'number') this[_onwrite](null, 0) + return this } write (buf, enc) { if (typeof buf === 'string') - buf = new Buffer(buf, enc) + buf = Buffer.from(buf, enc) if (this[_ended]) { this.emit('error', new Error('write() after end()')) @@ -330,8 +364,9 @@ class WriteStream extends EE { [_close] () { if (this[_autoClose] && typeof this[_fd] === 'number') { - fs.close(this[_fd], _ => this.emit('close')) + const fd = this[_fd] this[_fd] = null + fs.close(fd, er => er ? this.emit('error', er) : this.emit('close')) } } } @@ -339,47 +374,47 @@ class WriteStream extends EE { class WriteStreamSync extends WriteStream { [_open] () { let fd - try { + // only wrap in a try{} block if we know we'll retry, to avoid + // the rethrow obscuring the error's source frame in most cases. + if (this[_defaultFlag] && this[_flags] === 'r+') { + try { + fd = fs.openSync(this[_path], this[_flags], this[_mode]) + } catch (er) { + if (er.code === 'ENOENT') { + this[_flags] = 'w' + return this[_open]() + } else + throw er + } + } else fd = fs.openSync(this[_path], this[_flags], this[_mode]) - } catch (er) { - if (this[_defaultFlag] && - this[_flags] === 'r+' && - er && er.code === 'ENOENT') { - this[_flags] = 'w' - return this[_open]() - } else - throw er - } + this[_onopen](null, fd) } [_close] () { if (this[_autoClose] && typeof this[_fd] === 'number') { - try { - fs.closeSync(this[_fd]) - } catch (er) {} + const fd = this[_fd] this[_fd] = null + fs.closeSync(fd) this.emit('close') } } [_write] (buf) { + // throw the original, but try to close if it fails + let threw = true try { this[_onwrite](null, fs.writeSync(this[_fd], buf, 0, buf.length, this[_pos])) - } catch (er) { - this[_onwrite](er, 0) + threw = false + } finally { + if (threw) + try { this[_close]() } catch (_) {} } } } -const writev = (fd, iovec, pos, cb) => { - const done = (er, bw) => cb(er, bw, iovec) - const req = new FSReqWrap() - req.oncomplete = done - binding.writeBuffers(fd, iovec, pos, req) -} - exports.ReadStream = ReadStream exports.ReadStreamSync = ReadStreamSync diff --git a/node_modules/fs-minipass/package.json b/node_modules/fs-minipass/package.json index bb1d10567..2f2436cb5 100644 --- a/node_modules/fs-minipass/package.json +++ b/node_modules/fs-minipass/package.json @@ -1,41 +1,28 @@ { - "_from": "fs-minipass@^1.2.5", - "_id": "fs-minipass@1.2.7", - "_inBundle": false, - "_integrity": "sha512-GWSSJGFy4e9GUeCcbIkED+bgAoFyj7XF1mV8rma3QW4NIqX9Kyx79N/PF61H5udOV3aY1IaMLs6pGbH71nlCTA==", - "_location": "/fs-minipass", - "_phantomChildren": {}, - "_requested": { - "type": "range", - "registry": true, - "raw": "fs-minipass@^1.2.5", - "name": "fs-minipass", - "escapedName": "fs-minipass", - "rawSpec": "^1.2.5", - "saveSpec": null, - "fetchSpec": "^1.2.5" + "name": "fs-minipass", + "version": "2.1.0", + "main": "index.js", + "scripts": { + "test": "tap", + "preversion": "npm test", + "postversion": "npm publish", + "postpublish": "git push origin --follow-tags" }, - "_requiredBy": [ - "/node-gyp/tar" - ], - "_resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-1.2.7.tgz", - "_shasum": "ccff8570841e7fe4265693da88936c55aed7f7c7", - "_spec": "fs-minipass@^1.2.5", - "_where": "/Users/isaacs/dev/npm/cli/node_modules/node-gyp/node_modules/tar", - "author": { - "name": "Isaac Z. Schlueter", - "email": "i@izs.me", - "url": "http://blog.izs.me/" + "keywords": [], + "author": "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)", + "license": "ISC", + "repository": { + "type": "git", + "url": "git+https://github.com/npm/fs-minipass.git" }, "bugs": { "url": "https://github.com/npm/fs-minipass/issues" }, - "bundleDependencies": false, + "homepage": "https://github.com/npm/fs-minipass#readme", + "description": "fs read and write streams based on minipass", "dependencies": { - "minipass": "^2.6.0" + "minipass": "^3.0.0" }, - "deprecated": false, - "description": "fs read and write streams based on minipass", "devDependencies": { "mutate-fs": "^2.0.1", "tap": "^14.6.4" @@ -43,23 +30,10 @@ "files": [ "index.js" ], - "homepage": "https://github.com/npm/fs-minipass#readme", - "keywords": [], - "license": "ISC", - "main": "index.js", - "name": "fs-minipass", - "repository": { - "type": "git", - "url": "git+https://github.com/npm/fs-minipass.git" - }, - "scripts": { - "postpublish": "git push origin --follow-tags", - "postversion": "npm publish", - "preversion": "npm test", - "test": "tap" - }, "tap": { "check-coverage": true }, - "version": "1.2.7" + "engines": { + "node": ">= 8" + } } |