diff options
author | Florian Dold <florian.dold@gmail.com> | 2016-10-10 03:43:44 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2016-10-10 03:43:44 +0200 |
commit | abd94a7f5a50f43c797a11b53549ae48fff667c3 (patch) | |
tree | ab8ed457f65cdd72e13e0571d2975729428f1551 /node_modules/first-chunk-stream | |
parent | a0247c6a3fd6a09a41a7e35a3441324c4dcb58be (diff) | |
download | wallet-core-abd94a7f5a50f43c797a11b53549ae48fff667c3.tar.xz |
add node_modules to address #4364
Diffstat (limited to 'node_modules/first-chunk-stream')
-rw-r--r-- | node_modules/first-chunk-stream/index.js | 93 | ||||
-rw-r--r-- | node_modules/first-chunk-stream/package.json | 100 | ||||
-rw-r--r-- | node_modules/first-chunk-stream/readme.md | 62 |
3 files changed, 255 insertions, 0 deletions
diff --git a/node_modules/first-chunk-stream/index.js b/node_modules/first-chunk-stream/index.js new file mode 100644 index 000000000..24815508a --- /dev/null +++ b/node_modules/first-chunk-stream/index.js @@ -0,0 +1,93 @@ +'use strict'; +var util = require('util'); +var Transform = require('stream').Transform; + +function ctor(options, transform) { + util.inherits(FirstChunk, Transform); + + if (typeof options === 'function') { + transform = options; + options = {}; + } + + if (typeof transform !== 'function') { + throw new Error('transform function required'); + } + + function FirstChunk(options2) { + if (!(this instanceof FirstChunk)) { + return new FirstChunk(options2); + } + + Transform.call(this, options2); + + this._firstChunk = true; + this._transformCalled = false; + this._minSize = options.minSize; + } + + FirstChunk.prototype._transform = function (chunk, enc, cb) { + this._enc = enc; + + if (this._firstChunk) { + this._firstChunk = false; + + if (this._minSize == null) { + transform.call(this, chunk, enc, cb); + this._transformCalled = true; + return; + } + + this._buffer = chunk; + cb(); + return; + } + + if (this._minSize == null) { + this.push(chunk); + cb(); + return; + } + + if (this._buffer.length < this._minSize) { + this._buffer = Buffer.concat([this._buffer, chunk]); + cb(); + return; + } + + if (this._buffer.length >= this._minSize) { + transform.call(this, this._buffer.slice(), enc, function () { + this.push(chunk); + cb(); + }.bind(this)); + this._transformCalled = true; + this._buffer = false; + return; + } + + this.push(chunk); + cb(); + }; + + FirstChunk.prototype._flush = function (cb) { + if (!this._buffer) { + cb(); + return; + } + + if (this._transformCalled) { + this.push(this._buffer); + cb(); + } else { + transform.call(this, this._buffer.slice(), this._enc, cb); + } + }; + + return FirstChunk; +} + +module.exports = function () { + return ctor.apply(ctor, arguments)(); +}; + +module.exports.ctor = ctor; diff --git a/node_modules/first-chunk-stream/package.json b/node_modules/first-chunk-stream/package.json new file mode 100644 index 000000000..29ba43a7a --- /dev/null +++ b/node_modules/first-chunk-stream/package.json @@ -0,0 +1,100 @@ +{ + "_args": [ + [ + { + "raw": "first-chunk-stream@^1.0.0", + "scope": null, + "escapedName": "first-chunk-stream", + "name": "first-chunk-stream", + "rawSpec": "^1.0.0", + "spec": ">=1.0.0 <2.0.0", + "type": "range" + }, + "/home/dold/repos/taler/wallet-webex/node_modules/gulp/node_modules/strip-bom" + ] + ], + "_from": "first-chunk-stream@>=1.0.0 <2.0.0", + "_id": "first-chunk-stream@1.0.0", + "_inCache": true, + "_location": "/first-chunk-stream", + "_npmUser": { + "name": "sindresorhus", + "email": "sindresorhus@gmail.com" + }, + "_npmVersion": "1.4.21", + "_phantomChildren": {}, + "_requested": { + "raw": "first-chunk-stream@^1.0.0", + "scope": null, + "escapedName": "first-chunk-stream", + "name": "first-chunk-stream", + "rawSpec": "^1.0.0", + "spec": ">=1.0.0 <2.0.0", + "type": "range" + }, + "_requiredBy": [ + "/gulp/strip-bom", + "/strip-bom-stream" + ], + "_resolved": "https://registry.npmjs.org/first-chunk-stream/-/first-chunk-stream-1.0.0.tgz", + "_shasum": "59bfb50cd905f60d7c394cd3d9acaab4e6ad934e", + "_shrinkwrap": null, + "_spec": "first-chunk-stream@^1.0.0", + "_where": "/home/dold/repos/taler/wallet-webex/node_modules/gulp/node_modules/strip-bom", + "author": { + "name": "Sindre Sorhus", + "email": "sindresorhus@gmail.com", + "url": "http://sindresorhus.com" + }, + "bugs": { + "url": "https://github.com/sindresorhus/first-chunk-stream/issues" + }, + "dependencies": {}, + "description": "Transform the first chunk in a stream", + "devDependencies": { + "concat-stream": "^1.4.5", + "mocha": "*" + }, + "directories": {}, + "dist": { + "shasum": "59bfb50cd905f60d7c394cd3d9acaab4e6ad934e", + "tarball": "https://registry.npmjs.org/first-chunk-stream/-/first-chunk-stream-1.0.0.tgz" + }, + "engines": { + "node": ">=0.10.0" + }, + "files": [ + "index.js" + ], + "gitHead": "8b0b1750edcc30fa2b2071245198181e925be619", + "homepage": "https://github.com/sindresorhus/first-chunk-stream", + "keywords": [ + "buffer", + "stream", + "streams", + "transform", + "first", + "chunk", + "size", + "min", + "minimum" + ], + "license": "MIT", + "maintainers": [ + { + "name": "sindresorhus", + "email": "sindresorhus@gmail.com" + } + ], + "name": "first-chunk-stream", + "optionalDependencies": {}, + "readme": "ERROR: No README data found!", + "repository": { + "type": "git", + "url": "git+https://github.com/sindresorhus/first-chunk-stream.git" + }, + "scripts": { + "test": "mocha" + }, + "version": "1.0.0" +} diff --git a/node_modules/first-chunk-stream/readme.md b/node_modules/first-chunk-stream/readme.md new file mode 100644 index 000000000..f8909c8f7 --- /dev/null +++ b/node_modules/first-chunk-stream/readme.md @@ -0,0 +1,62 @@ +# first-chunk-stream [![Build Status](https://travis-ci.org/sindresorhus/first-chunk-stream.svg?branch=master)](https://travis-ci.org/sindresorhus/first-chunk-stream) + +> Transform the first chunk in a stream + +Useful if you want to do something to the first chunk. + +You can also set the minimum size of that chunk. + + +## Install + +```sh +$ npm install --save first-chunk-stream +``` + + +## Usage + +```js +var fs = require('fs'); +var concat = require('concat-stream'); +var firstChunk = require('first-chunk-stream'); + +// unicorn.txt => unicorn rainbow +// `highWaterMark: 1` means it will only read 1 byte at the time +fs.createReadStream('unicorn.txt', {highWaterMark: 1}) + .pipe(firstChunk({minSize: 7}, function (chunk, enc, cb) { + this.push(chunk.toUpperCase()); + cb(); + })) + .pipe(concat(function (data) { + console.log(data); + //=> UNICORN rainbow + })); +``` + + +## API + +### firstChunk([options], transform) + +#### options.minSize + +Type: `number` + +The minimum size of the first chunk. + +#### transform(chunk, encoding, callback) + +*Required* +Type: `function` + +The [function](http://nodejs.org/docs/latest/api/stream.html#stream_transform_transform_chunk_encoding_callback) that gets the first chunk. + +### firstChunk.ctor() + +Instead of returning a [stream.Transform](http://nodejs.org/docs/latest/api/stream.html#stream_class_stream_transform_1) instance, `firstChunk.ctor()` returns a constructor for a custom Transform. This is useful when you want to use the same transform logic in multiple instances. + + +## License + +MIT © [Sindre Sorhus](http://sindresorhus.com) |