bufferstreams
Advanced tools
Comparing version 1.1.2 to 1.1.3
{ | ||
"name": "bufferstreams", | ||
"version": "1.1.2", | ||
"version": "1.1.3", | ||
"description": "Abstract streams to deal with the whole buffered contents.", | ||
@@ -10,28 +10,9 @@ "homepage": "https://github.com/nfroidure/BufferStreams", | ||
], | ||
"metapak": { | ||
"configs": [ | ||
"readme", | ||
"eslint", | ||
"mocha", | ||
"codeclimate", | ||
"travis" | ||
], | ||
"data": { | ||
"files": "src/*.js tests/*.mocha.js", | ||
"testsFiles": "tests/*.mocha.js" | ||
} | ||
}, | ||
"scripts": { | ||
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s", | ||
"cli": "env NODE_ENV=${NODE_ENV:-cli}", | ||
"cover": "istanbul cover _mocha --report html -- tests/*.mocha.js -R spec -t 5000", | ||
"coveralls": "istanbul cover _mocha --report lcovonly -- tests/*.mocha.js -R spec -t 5000 && cat ./coverage/lcov.info | coveralls && rm -rf ./coverage", | ||
"cz": "env NODE_ENV=${NODE_ENV:-cli} git cz", | ||
"lint": "eslint src/*.js tests/*.mocha.js", | ||
"metapak": "metapak", | ||
"mocha": "mocha tests/*.mocha.js", | ||
"prettier": "prettier --write src/*.js tests/*.mocha.js", | ||
"preversion": "npm t && npm run lint && npm run metapak -s", | ||
"test": "npm run mocha", | ||
"version": "npm run changelog && git add CHANGELOG.md" | ||
"test": "mocha tests/*.mocha.js", | ||
"coveralls": "istanbul cover _mocha --report lcovonly -- tests/*.mocha.js -t 5000 && istanbul-coveralls", | ||
"cover": "istanbul cover --report html _mocha -- tests/*.mocha.js -t 5000", | ||
"trinity": "npm-check-updates -u && npm install && npm test && git commit package.json -m \"Dependencies update\" && git push", | ||
"lint": "eslint **/*.s", | ||
"cli": "env NPM_RUN_CLI=1" | ||
}, | ||
@@ -50,24 +31,19 @@ "repository": { | ||
"dependencies": { | ||
"debug": "2.6.1", | ||
"readable-stream": "^2.0.2" | ||
}, | ||
"devDependencies": { | ||
"commitizen": "^2.9.6", | ||
"conventional-changelog-cli": "^1.3.5", | ||
"coveralls": "^2.13.3", | ||
"cz-conventional-changelog": "^2.0.0", | ||
"eslint": "^4.12.1", | ||
"eslint-plugin-prettier": "^2.3.1", | ||
"istanbul": "^0.4.5", | ||
"eslint": "^1.0.0", | ||
"istanbul": "^0.3.17", | ||
"istanbul-coveralls": "^1.0.3", | ||
"metapak": "^1.0.2", | ||
"metapak-nfroidure": "^2.0.2", | ||
"mocha": "^3.5.3", | ||
"mocha-lcov-reporter": "^1.3.0", | ||
"prettier": "^1.8.2", | ||
"mocha": "^2.2.5", | ||
"mocha-lcov-reporter": "^0.0.2", | ||
"sf-lint": "^1.0.2", | ||
"streamtest": "^1.2.1" | ||
}, | ||
"author": "Nicolas Froidure", | ||
"author": { | ||
"name": "Nicolas Froidure", | ||
"url": "http://www.insertafter.com/blog.html" | ||
}, | ||
"engines": { | ||
"node": ">=6.9.5" | ||
"node": ">= 0.10.0" | ||
}, | ||
@@ -77,22 +53,3 @@ "license": "MIT", | ||
"url": "https://github.com/nfroidure/BufferStreams/issues" | ||
}, | ||
"config": { | ||
"commitizen": { | ||
"path": "./node_modules/cz-conventional-changelog" | ||
} | ||
}, | ||
"greenkeeper": { | ||
"ignore": [ | ||
"commitizen", | ||
"cz-conventional-changelog", | ||
"conventional-changelog-cli", | ||
"eslint", | ||
"eslint-config-prettier", | ||
"prettier", | ||
"mocha", | ||
"mocha-lcov-reporter", | ||
"coveralls", | ||
"istanbul" | ||
] | ||
} | ||
} |
@@ -1,16 +0,9 @@ | ||
<!-- | ||
# This file is automatically generated by a `metapak` | ||
# module. Do not change it elsewhere, changes would | ||
# be overridden. | ||
--> | ||
# bufferstreams | ||
> Abstract streams to deal with the whole buffered contents. | ||
# BufferStreams | ||
[![NPM version](https://badge.fury.io/js/bufferstreams.svg)](https://npmjs.org/package/bufferstreams) | ||
[![Build status](https://secure.travis-ci.org/nfroidure/bufferstreams.svg)](https://travis-ci.org/nfroidure/bufferstreams) | ||
[![NPM version](https://img.shields.io/npm/v/bufferstreams.svg)](https://www.npmjs.com/package/bufferstreams) | ||
[![Build Status](https://travis-ci.org/nfroidure/BufferStreams.svg?branch=master)](https://travis-ci.org/nfroidure/BufferStreams) | ||
[![Dependency Status](https://david-dm.org/nfroidure/bufferstreams.svg)](https://david-dm.org/nfroidure/bufferstreams) | ||
[![devDependency Status](https://david-dm.org/nfroidure/bufferstreams/dev-status.svg)](https://david-dm.org/nfroidure/bufferstreams#info=devDependencies) | ||
[![Coverage Status](https://coveralls.io/repos/nfroidure/bufferstreams/badge.svg?branch=master)](https://coveralls.io/r/nfroidure/bufferstreams?branch=master) | ||
[![Code Climate](https://codeclimate.com/github/nfroidure/bufferstreams.svg)](https://codeclimate.com/github/nfroidure/bufferstreams) | ||
[![Dependency Status](https://dependencyci.com/github/nfroidure/bufferstreams/badge)](https://dependencyci.com/github/nfroidure/bufferstreams) | ||
[![Coverage Status](https://coveralls.io/repos/nfroidure/BufferStreams/badge.svg?branch=master)](https://coveralls.io/r/nfroidure/BufferStreams?branch=master) | ||
[![Code Climate](https://codeclimate.com/github/nfroidure/BufferStreams/badges/gpa.svg)](https://codeclimate.com/github/nfroidure/BufferStreams) | ||
@@ -94,4 +87,1 @@ `bufferstreams` abstracts streams to allow you to deal with their whole content | ||
Feel free to pull your code if you agree with publishing it under the MIT license. | ||
# License | ||
[MIT](https://github.com/nfroidure/bufferstreams/blob/master/LICENSE) |
'use strict'; | ||
const Duplex = require('readable-stream').Duplex; | ||
const util = require('util'); | ||
var Duplex = require('readable-stream').Duplex; | ||
var util = require('util'); | ||
@@ -11,6 +11,6 @@ // Inherit of Duplex stream | ||
function BufferStream(options, cb) { | ||
const _this = this; | ||
var _this = this; | ||
// Ensure new were used | ||
if (!(_this instanceof BufferStream)) { | ||
if (!(this instanceof BufferStream)) { | ||
return new BufferStream(options, cb); | ||
@@ -20,3 +20,3 @@ } | ||
// Cast args | ||
if (options instanceof Function) { | ||
if(options instanceof Function) { | ||
cb = options; | ||
@@ -26,41 +26,45 @@ options = {}; | ||
options = options || {}; | ||
if (!(cb instanceof Function)) { | ||
if(!(cb instanceof Function)) { | ||
throw new Error('The given callback must be a function.'); | ||
} | ||
_this.__objectMode = options.objectMode; | ||
this.__objectMode = options.objectMode; | ||
// Parent constructor | ||
Duplex.call(_this, options); | ||
Duplex.call(this, options); | ||
// Keep a reference to the callback | ||
_this._cb = cb; | ||
this._cb = cb; | ||
// Add a finished flag | ||
_this._bufferStreamFinished = false; | ||
this._bufferStreamFinished = false; | ||
// Internal buffer | ||
_this._bufferStreamBuffer = []; | ||
this._bufferStreamBuffer = []; | ||
// Internal logic | ||
function _bufferStreamCallbackWrapper(err) { | ||
const buffer = options.objectMode | ||
? _this._bufferStreamBuffer | ||
: Buffer.concat(_this._bufferStreamBuffer); | ||
var buffer = options.objectMode ? | ||
_this._bufferStreamBuffer : | ||
Buffer.concat(_this._bufferStreamBuffer); | ||
err = err || null; | ||
_this._cb(err, buffer, (err2, buf) => { | ||
setImmediate(() => { | ||
_this.removeListener('error', _bufferStreamError); | ||
if (err2) { | ||
_this.emit('error', err2); | ||
} | ||
_this._bufferStreamBuffer = options.objectMode ? buf || [] : [buf]; | ||
_this._bufferStreamFinished = true; | ||
_this._read(); | ||
}); | ||
}); | ||
_this._cb( | ||
err, | ||
buffer, | ||
function(err2, buf) { | ||
setImmediate(function() { | ||
_this.removeListener('error', _bufferStreamError); | ||
if(err2) { | ||
_this.emit('error', err2); | ||
} | ||
_this._bufferStreamBuffer = options.objectMode ? buf || [] : [buf]; | ||
_this._bufferStreamFinished = true; | ||
_this._read(); | ||
}); | ||
} | ||
); | ||
} | ||
function _bufferStreamError(err) { | ||
if (_this._bufferStreamFinished) { | ||
if(_this._bufferStreamFinished) { | ||
return; | ||
@@ -71,12 +75,8 @@ } | ||
_this.once('finish', _bufferStreamCallbackWrapper); | ||
this.once('finish', _bufferStreamCallbackWrapper); | ||
_this.on('error', _bufferStreamError); | ||
this.on('error', _bufferStreamError); | ||
} | ||
BufferStream.prototype._write = function _bufferStreamWrite( | ||
chunk, | ||
encoding, | ||
done | ||
) { | ||
BufferStream.prototype._write = function _bufferStreamWrite(chunk, encoding, done) { | ||
this._bufferStreamBuffer.push(chunk); | ||
@@ -86,17 +86,18 @@ done(); | ||
BufferStream.prototype._read = function _bufferStreamRead() { | ||
const _this = this; | ||
BufferStream.prototype._read = function _bufferStreamRead(n) { | ||
var _this = this; | ||
if (_this._bufferStreamFinished) { | ||
while (_this._bufferStreamBuffer.length) { | ||
if (!_this.push(_this._bufferStreamBuffer.shift())) { | ||
if(_this._bufferStreamFinished) { | ||
while(_this._bufferStreamBuffer.length) { | ||
if(!_this.push(_this._bufferStreamBuffer.shift())) { | ||
break; | ||
} | ||
} | ||
if (0 === _this._bufferStreamBuffer.length) { | ||
if(0 === _this._bufferStreamBuffer.length) { | ||
_this.push(null); | ||
} | ||
} | ||
}; | ||
module.exports = BufferStream; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1
7
7909
4
87
- Removeddebug@2.6.1
- Removeddebug@2.6.1(transitive)
- Removedms@0.7.2(transitive)