Template Upload
This commit is contained in:
72
node_modules/read-all-stream/index.js
generated
vendored
Normal file
72
node_modules/read-all-stream/index.js
generated
vendored
Normal file
@ -0,0 +1,72 @@
|
||||
'use strict';
|
||||
|
||||
var Writable = require('readable-stream').Writable;
|
||||
var inherits = require('util').inherits;
|
||||
var Promise = require('pinkie-promise');
|
||||
|
||||
function BufferStream() {
|
||||
Writable.call(this, { objectMode: true });
|
||||
this.buffer = [];
|
||||
this.length = 0;
|
||||
}
|
||||
|
||||
inherits(BufferStream, Writable);
|
||||
BufferStream.prototype._write = function(chunk, enc, next) {
|
||||
if (!Buffer.isBuffer(chunk)) {
|
||||
chunk = new Buffer(chunk);
|
||||
}
|
||||
|
||||
this.buffer.push(chunk);
|
||||
this.length += chunk.length;
|
||||
next();
|
||||
};
|
||||
|
||||
module.exports = function read(stream, options, cb) {
|
||||
if (!stream) {
|
||||
throw new Error('stream argument is required');
|
||||
}
|
||||
|
||||
if (typeof options === 'function') {
|
||||
cb = options;
|
||||
options = {};
|
||||
}
|
||||
|
||||
if (typeof options === 'string' || options === undefined || options === null) {
|
||||
options = { encoding: options };
|
||||
}
|
||||
|
||||
if (options.encoding === undefined) { options.encoding = 'utf8'; }
|
||||
|
||||
var promise;
|
||||
|
||||
if (!cb) {
|
||||
var resolve, reject;
|
||||
promise = new Promise(function(_res, _rej) {
|
||||
resolve = _res;
|
||||
reject = _rej;
|
||||
});
|
||||
|
||||
cb = function (err, data) {
|
||||
if (err) { return reject(err); }
|
||||
resolve(data);
|
||||
};
|
||||
}
|
||||
|
||||
var sink = new BufferStream();
|
||||
|
||||
sink.on('finish', function () {
|
||||
var data = Buffer.concat(this.buffer, this.length);
|
||||
|
||||
if (options.encoding) {
|
||||
data = data.toString(options.encoding);
|
||||
}
|
||||
|
||||
cb(null, data);
|
||||
});
|
||||
|
||||
stream.once('error', cb);
|
||||
|
||||
stream.pipe(sink);
|
||||
|
||||
return promise;
|
||||
}
|
21
node_modules/read-all-stream/license
generated
vendored
Normal file
21
node_modules/read-all-stream/license
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) Vsevolod Strukchinsky <floatdrop@gmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
87
node_modules/read-all-stream/package.json
generated
vendored
Normal file
87
node_modules/read-all-stream/package.json
generated
vendored
Normal file
@ -0,0 +1,87 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"read-all-stream@^3.0.0",
|
||||
"C:\\Users\\x2mjbyrn\\Source\\Repos\\Skeleton\\node_modules\\got"
|
||||
]
|
||||
],
|
||||
"_from": "read-all-stream@>=3.0.0-0 <4.0.0-0",
|
||||
"_id": "read-all-stream@3.1.0",
|
||||
"_inCache": true,
|
||||
"_location": "/read-all-stream",
|
||||
"_nodeVersion": "4.2.4",
|
||||
"_npmUser": {
|
||||
"email": "floatdrop@gmail.com",
|
||||
"name": "floatdrop"
|
||||
},
|
||||
"_npmVersion": "2.14.12",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"name": "read-all-stream",
|
||||
"raw": "read-all-stream@^3.0.0",
|
||||
"rawSpec": "^3.0.0",
|
||||
"scope": null,
|
||||
"spec": ">=3.0.0-0 <4.0.0-0",
|
||||
"type": "range"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/got"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/read-all-stream/-/read-all-stream-3.1.0.tgz",
|
||||
"_shasum": "35c3e177f2078ef789ee4bfafa4373074eaef4fa",
|
||||
"_shrinkwrap": null,
|
||||
"_spec": "read-all-stream@^3.0.0",
|
||||
"_where": "C:\\Users\\x2mjbyrn\\Source\\Repos\\Skeleton\\node_modules\\got",
|
||||
"author": {
|
||||
"email": "floatdrop@gmail.com",
|
||||
"name": "Vsevolod Strukchinsky"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/floatdrop/read-all-stream/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"pinkie-promise": "^2.0.0",
|
||||
"readable-stream": "^2.0.0"
|
||||
},
|
||||
"description": "Read all stream content and pass it to callback",
|
||||
"devDependencies": {
|
||||
"mocha": "*"
|
||||
},
|
||||
"directories": {},
|
||||
"dist": {
|
||||
"shasum": "35c3e177f2078ef789ee4bfafa4373074eaef4fa",
|
||||
"tarball": "https://registry.npmjs.org/read-all-stream/-/read-all-stream-3.1.0.tgz"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
},
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"gitHead": "636cb4f64d9bf5261c7c42d257071b528caa7888",
|
||||
"homepage": "https://github.com/floatdrop/read-all-stream",
|
||||
"installable": true,
|
||||
"keywords": [
|
||||
"buffer",
|
||||
"callback",
|
||||
"read",
|
||||
"stream"
|
||||
],
|
||||
"license": "MIT",
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "floatdrop",
|
||||
"email": "floatdrop@gmail.com"
|
||||
}
|
||||
],
|
||||
"name": "read-all-stream",
|
||||
"optionalDependencies": {},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/floatdrop/read-all-stream"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "mocha"
|
||||
},
|
||||
"version": "3.1.0"
|
||||
}
|
72
node_modules/read-all-stream/readme.md
generated
vendored
Normal file
72
node_modules/read-all-stream/readme.md
generated
vendored
Normal file
@ -0,0 +1,72 @@
|
||||
# read-all-stream [![Build Status][travis-image]][travis-url]
|
||||
|
||||
> Read stream to buffer or string
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install --save read-all-stream
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
var read = require('read-all-stream');
|
||||
var stream = fs.createReadStream('index.js');
|
||||
|
||||
read(stream).then(function (data) {
|
||||
console.log(data.length);
|
||||
});
|
||||
|
||||
read(stream, 'utf8', function (err, data) {
|
||||
console.log(data.length);
|
||||
//=> 42
|
||||
});
|
||||
|
||||
```
|
||||
|
||||
### API
|
||||
|
||||
#### read(stream, [options], [callback])
|
||||
|
||||
If callback is omitted, Promise will be returned.
|
||||
|
||||
##### stream
|
||||
|
||||
*Required*
|
||||
Type: `Stream`
|
||||
|
||||
Event emitter, which `data` events will be consumed.
|
||||
|
||||
##### options
|
||||
|
||||
Type: `object` or `string`
|
||||
|
||||
If type of `options` is `string`, then it will be used as encoding.
|
||||
If type is `Object`, then next options are available:
|
||||
|
||||
##### options.encoding
|
||||
|
||||
Type: `string`, `null`
|
||||
Default: `'utf8'`
|
||||
|
||||
Encoding to be used on `toString` of the data. If null, the body is returned as a Buffer.
|
||||
|
||||
##### callback(err, data)
|
||||
|
||||
Will be called after stream is read.
|
||||
|
||||
###### err
|
||||
|
||||
`Error` object (if `error` event happens).
|
||||
|
||||
###### data
|
||||
|
||||
The data in stream.
|
||||
|
||||
## License
|
||||
|
||||
MIT © [Vsevolod Strukchinsky](floatdrop@gmail.com)
|
||||
|
||||
[travis-url]: https://travis-ci.org/floatdrop/read-all-stream
|
||||
[travis-image]: https://img.shields.io/travis/floatdrop/read-all-stream.svg
|
Reference in New Issue
Block a user