done purchases remove, ocr scan, read image
This commit is contained in:
17
express-server/node_modules/busboy/.travis.yml
generated
vendored
Normal file
17
express-server/node_modules/busboy/.travis.yml
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
sudo: false
|
||||
language: cpp
|
||||
notifications:
|
||||
email: false
|
||||
env:
|
||||
matrix:
|
||||
- TRAVIS_NODE_VERSION="0.10"
|
||||
- TRAVIS_NODE_VERSION="0.12"
|
||||
- TRAVIS_NODE_VERSION="4"
|
||||
- TRAVIS_NODE_VERSION="6"
|
||||
- TRAVIS_NODE_VERSION="7"
|
||||
install:
|
||||
- rm -rf ~/.nvm && git clone https://github.com/creationix/nvm.git ~/.nvm && source ~/.nvm/nvm.sh && nvm install $TRAVIS_NODE_VERSION
|
||||
- node --version
|
||||
- npm --version
|
||||
- npm install
|
||||
script: npm test
|
19
express-server/node_modules/busboy/LICENSE
generated
vendored
Normal file
19
express-server/node_modules/busboy/LICENSE
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
Copyright Brian White. All rights reserved.
|
||||
|
||||
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.
|
225
express-server/node_modules/busboy/README.md
generated
vendored
Normal file
225
express-server/node_modules/busboy/README.md
generated
vendored
Normal file
@ -0,0 +1,225 @@
|
||||
Description
|
||||
===========
|
||||
|
||||
A node.js module for parsing incoming HTML form data.
|
||||
|
||||
If you've found this module to be useful and wish to support it, you may do so by visiting this pledgie campaign:
|
||||
<a href='https://pledgie.com/campaigns/28774'><img alt='Click here to support busboy' src='https://pledgie.com/campaigns/28774.png?skin_name=chrome' border='0'></a>
|
||||
|
||||
|
||||
Requirements
|
||||
============
|
||||
|
||||
* [node.js](http://nodejs.org/) -- v0.8.0 or newer
|
||||
|
||||
|
||||
Install
|
||||
=======
|
||||
|
||||
npm install busboy
|
||||
|
||||
|
||||
Examples
|
||||
========
|
||||
|
||||
* Parsing (multipart) with default options:
|
||||
|
||||
```javascript
|
||||
var http = require('http'),
|
||||
inspect = require('util').inspect;
|
||||
|
||||
var Busboy = require('busboy');
|
||||
|
||||
http.createServer(function(req, res) {
|
||||
if (req.method === 'POST') {
|
||||
var busboy = new Busboy({ headers: req.headers });
|
||||
busboy.on('file', function(fieldname, file, filename, encoding, mimetype) {
|
||||
console.log('File [' + fieldname + ']: filename: ' + filename + ', encoding: ' + encoding + ', mimetype: ' + mimetype);
|
||||
file.on('data', function(data) {
|
||||
console.log('File [' + fieldname + '] got ' + data.length + ' bytes');
|
||||
});
|
||||
file.on('end', function() {
|
||||
console.log('File [' + fieldname + '] Finished');
|
||||
});
|
||||
});
|
||||
busboy.on('field', function(fieldname, val, fieldnameTruncated, valTruncated, encoding, mimetype) {
|
||||
console.log('Field [' + fieldname + ']: value: ' + inspect(val));
|
||||
});
|
||||
busboy.on('finish', function() {
|
||||
console.log('Done parsing form!');
|
||||
res.writeHead(303, { Connection: 'close', Location: '/' });
|
||||
res.end();
|
||||
});
|
||||
req.pipe(busboy);
|
||||
} else if (req.method === 'GET') {
|
||||
res.writeHead(200, { Connection: 'close' });
|
||||
res.end('<html><head></head><body>\
|
||||
<form method="POST" enctype="multipart/form-data">\
|
||||
<input type="text" name="textfield"><br />\
|
||||
<input type="file" name="filefield"><br />\
|
||||
<input type="submit">\
|
||||
</form>\
|
||||
</body></html>');
|
||||
}
|
||||
}).listen(8000, function() {
|
||||
console.log('Listening for requests');
|
||||
});
|
||||
|
||||
// Example output, using http://nodejs.org/images/ryan-speaker.jpg as the file:
|
||||
//
|
||||
// Listening for requests
|
||||
// File [filefield]: filename: ryan-speaker.jpg, encoding: binary
|
||||
// File [filefield] got 11971 bytes
|
||||
// Field [textfield]: value: 'testing! :-)'
|
||||
// File [filefield] Finished
|
||||
// Done parsing form!
|
||||
```
|
||||
|
||||
* Save all incoming files to disk:
|
||||
|
||||
```javascript
|
||||
var http = require('http'),
|
||||
path = require('path'),
|
||||
os = require('os'),
|
||||
fs = require('fs');
|
||||
|
||||
var Busboy = require('busboy');
|
||||
|
||||
http.createServer(function(req, res) {
|
||||
if (req.method === 'POST') {
|
||||
var busboy = new Busboy({ headers: req.headers });
|
||||
busboy.on('file', function(fieldname, file, filename, encoding, mimetype) {
|
||||
var saveTo = path.join(os.tmpDir(), path.basename(fieldname));
|
||||
file.pipe(fs.createWriteStream(saveTo));
|
||||
});
|
||||
busboy.on('finish', function() {
|
||||
res.writeHead(200, { 'Connection': 'close' });
|
||||
res.end("That's all folks!");
|
||||
});
|
||||
return req.pipe(busboy);
|
||||
}
|
||||
res.writeHead(404);
|
||||
res.end();
|
||||
}).listen(8000, function() {
|
||||
console.log('Listening for requests');
|
||||
});
|
||||
```
|
||||
|
||||
* Parsing (urlencoded) with default options:
|
||||
|
||||
```javascript
|
||||
var http = require('http'),
|
||||
inspect = require('util').inspect;
|
||||
|
||||
var Busboy = require('busboy');
|
||||
|
||||
http.createServer(function(req, res) {
|
||||
if (req.method === 'POST') {
|
||||
var busboy = new Busboy({ headers: req.headers });
|
||||
busboy.on('file', function(fieldname, file, filename, encoding, mimetype) {
|
||||
console.log('File [' + fieldname + ']: filename: ' + filename);
|
||||
file.on('data', function(data) {
|
||||
console.log('File [' + fieldname + '] got ' + data.length + ' bytes');
|
||||
});
|
||||
file.on('end', function() {
|
||||
console.log('File [' + fieldname + '] Finished');
|
||||
});
|
||||
});
|
||||
busboy.on('field', function(fieldname, val, fieldnameTruncated, valTruncated) {
|
||||
console.log('Field [' + fieldname + ']: value: ' + inspect(val));
|
||||
});
|
||||
busboy.on('finish', function() {
|
||||
console.log('Done parsing form!');
|
||||
res.writeHead(303, { Connection: 'close', Location: '/' });
|
||||
res.end();
|
||||
});
|
||||
req.pipe(busboy);
|
||||
} else if (req.method === 'GET') {
|
||||
res.writeHead(200, { Connection: 'close' });
|
||||
res.end('<html><head></head><body>\
|
||||
<form method="POST">\
|
||||
<input type="text" name="textfield"><br />\
|
||||
<select name="selectfield">\
|
||||
<option value="1">1</option>\
|
||||
<option value="10">10</option>\
|
||||
<option value="100">100</option>\
|
||||
<option value="9001">9001</option>\
|
||||
</select><br />\
|
||||
<input type="checkbox" name="checkfield">Node.js rules!<br />\
|
||||
<input type="submit">\
|
||||
</form>\
|
||||
</body></html>');
|
||||
}
|
||||
}).listen(8000, function() {
|
||||
console.log('Listening for requests');
|
||||
});
|
||||
|
||||
// Example output:
|
||||
//
|
||||
// Listening for requests
|
||||
// Field [textfield]: value: 'testing! :-)'
|
||||
// Field [selectfield]: value: '9001'
|
||||
// Field [checkfield]: value: 'on'
|
||||
// Done parsing form!
|
||||
```
|
||||
|
||||
|
||||
API
|
||||
===
|
||||
|
||||
_Busboy_ is a _Writable_ stream
|
||||
|
||||
Busboy (special) events
|
||||
-----------------------
|
||||
|
||||
* **file**(< _string_ >fieldname, < _ReadableStream_ >stream, < _string_ >filename, < _string_ >transferEncoding, < _string_ >mimeType) - Emitted for each new file form field found. `transferEncoding` contains the 'Content-Transfer-Encoding' value for the file stream. `mimeType` contains the 'Content-Type' value for the file stream.
|
||||
* Note: if you listen for this event, you should always handle the `stream` no matter if you care about the file contents or not (e.g. you can simply just do `stream.resume();` if you want to discard the contents), otherwise the 'finish' event will never fire on the Busboy instance. However, if you don't care about **any** incoming files, you can simply not listen for the 'file' event at all and any/all files will be automatically and safely discarded (these discarded files do still count towards `files` and `parts` limits).
|
||||
* If a configured file size limit was reached, `stream` will both have a boolean property `truncated` (best checked at the end of the stream) and emit a 'limit' event to notify you when this happens.
|
||||
|
||||
* **field**(< _string_ >fieldname, < _string_ >value, < _boolean_ >fieldnameTruncated, < _boolean_ >valueTruncated, < _string_ >transferEncoding, < _string_ >mimeType) - Emitted for each new non-file field found.
|
||||
|
||||
* **partsLimit**() - Emitted when specified `parts` limit has been reached. No more 'file' or 'field' events will be emitted.
|
||||
|
||||
* **filesLimit**() - Emitted when specified `files` limit has been reached. No more 'file' events will be emitted.
|
||||
|
||||
* **fieldsLimit**() - Emitted when specified `fields` limit has been reached. No more 'field' events will be emitted.
|
||||
|
||||
|
||||
Busboy methods
|
||||
--------------
|
||||
|
||||
* **(constructor)**(< _object_ >config) - Creates and returns a new Busboy instance.
|
||||
|
||||
* The constructor takes the following valid `config` settings:
|
||||
|
||||
* **headers** - _object_ - These are the HTTP headers of the incoming request, which are used by individual parsers.
|
||||
|
||||
* **highWaterMark** - _integer_ - highWaterMark to use for this Busboy instance (Default: WritableStream default).
|
||||
|
||||
* **fileHwm** - _integer_ - highWaterMark to use for file streams (Default: ReadableStream default).
|
||||
|
||||
* **defCharset** - _string_ - Default character set to use when one isn't defined (Default: 'utf8').
|
||||
|
||||
* **preservePath** - _boolean_ - If paths in the multipart 'filename' field shall be preserved. (Default: false).
|
||||
|
||||
* **limits** - _object_ - Various limits on incoming data. Valid properties are:
|
||||
|
||||
* **fieldNameSize** - _integer_ - Max field name size (in bytes) (Default: 100 bytes).
|
||||
|
||||
* **fieldSize** - _integer_ - Max field value size (in bytes) (Default: 1MB).
|
||||
|
||||
* **fields** - _integer_ - Max number of non-file fields (Default: Infinity).
|
||||
|
||||
* **fileSize** - _integer_ - For multipart forms, the max file size (in bytes) (Default: Infinity).
|
||||
|
||||
* **files** - _integer_ - For multipart forms, the max number of file fields (Default: Infinity).
|
||||
|
||||
* **parts** - _integer_ - For multipart forms, the max number of parts (fields + files) (Default: Infinity).
|
||||
|
||||
* **headerPairs** - _integer_ - For multipart forms, the max number of header key=>value pairs to parse **Default:** 2000 (same as node's http).
|
||||
|
||||
* The constructor can throw errors:
|
||||
|
||||
* **Unsupported content type: $type** - The `Content-Type` isn't one Busboy can parse.
|
||||
|
||||
* **Missing Content-Type** - The provided headers don't include `Content-Type` at all.
|
73
express-server/node_modules/busboy/deps/encoding/encoding-indexes.js
generated
vendored
Normal file
73
express-server/node_modules/busboy/deps/encoding/encoding-indexes.js
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
2391
express-server/node_modules/busboy/deps/encoding/encoding.js
generated
vendored
Normal file
2391
express-server/node_modules/busboy/deps/encoding/encoding.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
89
express-server/node_modules/busboy/lib/main.js
generated
vendored
Normal file
89
express-server/node_modules/busboy/lib/main.js
generated
vendored
Normal file
@ -0,0 +1,89 @@
|
||||
var fs = require('fs'),
|
||||
WritableStream = require('stream').Writable
|
||||
|| require('readable-stream').Writable,
|
||||
inherits = require('util').inherits;
|
||||
|
||||
var parseParams = require('./utils').parseParams;
|
||||
|
||||
function Busboy(opts) {
|
||||
if (!(this instanceof Busboy))
|
||||
return new Busboy(opts);
|
||||
if (opts.highWaterMark !== undefined)
|
||||
WritableStream.call(this, { highWaterMark: opts.highWaterMark });
|
||||
else
|
||||
WritableStream.call(this);
|
||||
|
||||
this._done = false;
|
||||
this._parser = undefined;
|
||||
this._finished = false;
|
||||
|
||||
this.opts = opts;
|
||||
if (opts.headers && typeof opts.headers['content-type'] === 'string')
|
||||
this.parseHeaders(opts.headers);
|
||||
else
|
||||
throw new Error('Missing Content-Type');
|
||||
}
|
||||
inherits(Busboy, WritableStream);
|
||||
|
||||
Busboy.prototype.emit = function(ev) {
|
||||
if (ev === 'finish') {
|
||||
if (!this._done) {
|
||||
this._parser && this._parser.end();
|
||||
return;
|
||||
} else if (this._finished) {
|
||||
return;
|
||||
}
|
||||
this._finished = true;
|
||||
}
|
||||
WritableStream.prototype.emit.apply(this, arguments);
|
||||
};
|
||||
|
||||
Busboy.prototype.parseHeaders = function(headers) {
|
||||
this._parser = undefined;
|
||||
if (headers['content-type']) {
|
||||
var parsed = parseParams(headers['content-type']),
|
||||
matched, type;
|
||||
for (var i = 0; i < TYPES.length; ++i) {
|
||||
type = TYPES[i];
|
||||
if (typeof type.detect === 'function')
|
||||
matched = type.detect(parsed);
|
||||
else
|
||||
matched = type.detect.test(parsed[0]);
|
||||
if (matched)
|
||||
break;
|
||||
}
|
||||
if (matched) {
|
||||
var cfg = {
|
||||
limits: this.opts.limits,
|
||||
headers: headers,
|
||||
parsedConType: parsed,
|
||||
highWaterMark: undefined,
|
||||
fileHwm: undefined,
|
||||
defCharset: undefined,
|
||||
preservePath: false
|
||||
};
|
||||
if (this.opts.highWaterMark)
|
||||
cfg.highWaterMark = this.opts.highWaterMark;
|
||||
if (this.opts.fileHwm)
|
||||
cfg.fileHwm = this.opts.fileHwm;
|
||||
cfg.defCharset = this.opts.defCharset;
|
||||
cfg.preservePath = this.opts.preservePath;
|
||||
this._parser = type(this, cfg);
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new Error('Unsupported content type: ' + headers['content-type']);
|
||||
};
|
||||
|
||||
Busboy.prototype._write = function(chunk, encoding, cb) {
|
||||
if (!this._parser)
|
||||
return cb(new Error('Not ready to parse. Missing Content-Type?'));
|
||||
this._parser.write(chunk, cb);
|
||||
};
|
||||
|
||||
var TYPES = [
|
||||
require('./types/multipart'),
|
||||
require('./types/urlencoded'),
|
||||
];
|
||||
|
||||
module.exports = Busboy;
|
324
express-server/node_modules/busboy/lib/types/multipart.js
generated
vendored
Normal file
324
express-server/node_modules/busboy/lib/types/multipart.js
generated
vendored
Normal file
@ -0,0 +1,324 @@
|
||||
// TODO:
|
||||
// * support 1 nested multipart level
|
||||
// (see second multipart example here:
|
||||
// http://www.w3.org/TR/html401/interact/forms.html#didx-multipartform-data)
|
||||
// * support limits.fieldNameSize
|
||||
// -- this will require modifications to utils.parseParams
|
||||
|
||||
var ReadableStream = require('stream').Readable || require('readable-stream'),
|
||||
inherits = require('util').inherits;
|
||||
|
||||
var Dicer = require('dicer');
|
||||
|
||||
var parseParams = require('../utils').parseParams,
|
||||
decodeText = require('../utils').decodeText,
|
||||
basename = require('../utils').basename;
|
||||
|
||||
var RE_BOUNDARY = /^boundary$/i,
|
||||
RE_FIELD = /^form-data$/i,
|
||||
RE_CHARSET = /^charset$/i,
|
||||
RE_FILENAME = /^filename$/i,
|
||||
RE_NAME = /^name$/i;
|
||||
|
||||
Multipart.detect = /^multipart\/form-data/i;
|
||||
function Multipart(boy, cfg) {
|
||||
if (!(this instanceof Multipart))
|
||||
return new Multipart(boy, cfg);
|
||||
var i,
|
||||
len,
|
||||
self = this,
|
||||
boundary,
|
||||
limits = cfg.limits,
|
||||
parsedConType = cfg.parsedConType || [],
|
||||
defCharset = cfg.defCharset || 'utf8',
|
||||
preservePath = cfg.preservePath,
|
||||
fileopts = (typeof cfg.fileHwm === 'number'
|
||||
? { highWaterMark: cfg.fileHwm }
|
||||
: {});
|
||||
|
||||
for (i = 0, len = parsedConType.length; i < len; ++i) {
|
||||
if (Array.isArray(parsedConType[i])
|
||||
&& RE_BOUNDARY.test(parsedConType[i][0])) {
|
||||
boundary = parsedConType[i][1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function checkFinished() {
|
||||
if (nends === 0 && finished && !boy._done) {
|
||||
finished = false;
|
||||
process.nextTick(function() {
|
||||
boy._done = true;
|
||||
boy.emit('finish');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof boundary !== 'string')
|
||||
throw new Error('Multipart: Boundary not found');
|
||||
|
||||
var fieldSizeLimit = (limits && typeof limits.fieldSize === 'number'
|
||||
? limits.fieldSize
|
||||
: 1 * 1024 * 1024),
|
||||
fileSizeLimit = (limits && typeof limits.fileSize === 'number'
|
||||
? limits.fileSize
|
||||
: Infinity),
|
||||
filesLimit = (limits && typeof limits.files === 'number'
|
||||
? limits.files
|
||||
: Infinity),
|
||||
fieldsLimit = (limits && typeof limits.fields === 'number'
|
||||
? limits.fields
|
||||
: Infinity),
|
||||
partsLimit = (limits && typeof limits.parts === 'number'
|
||||
? limits.parts
|
||||
: Infinity);
|
||||
|
||||
var nfiles = 0,
|
||||
nfields = 0,
|
||||
nends = 0,
|
||||
curFile,
|
||||
curField,
|
||||
finished = false;
|
||||
|
||||
this._needDrain = false;
|
||||
this._pause = false;
|
||||
this._cb = undefined;
|
||||
this._nparts = 0;
|
||||
this._boy = boy;
|
||||
|
||||
var parserCfg = {
|
||||
boundary: boundary,
|
||||
maxHeaderPairs: (limits && limits.headerPairs)
|
||||
};
|
||||
if (fileopts.highWaterMark)
|
||||
parserCfg.partHwm = fileopts.highWaterMark;
|
||||
if (cfg.highWaterMark)
|
||||
parserCfg.highWaterMark = cfg.highWaterMark;
|
||||
|
||||
this.parser = new Dicer(parserCfg);
|
||||
this.parser.on('drain', function() {
|
||||
self._needDrain = false;
|
||||
if (self._cb && !self._pause) {
|
||||
var cb = self._cb;
|
||||
self._cb = undefined;
|
||||
cb();
|
||||
}
|
||||
}).on('part', function onPart(part) {
|
||||
if (++self._nparts > partsLimit) {
|
||||
self.parser.removeListener('part', onPart);
|
||||
self.parser.on('part', skipPart);
|
||||
boy.hitPartsLimit = true;
|
||||
boy.emit('partsLimit');
|
||||
return skipPart(part);
|
||||
}
|
||||
|
||||
// hack because streams2 _always_ doesn't emit 'end' until nextTick, so let
|
||||
// us emit 'end' early since we know the part has ended if we are already
|
||||
// seeing the next part
|
||||
if (curField) {
|
||||
var field = curField;
|
||||
field.emit('end');
|
||||
field.removeAllListeners('end');
|
||||
}
|
||||
|
||||
part.on('header', function(header) {
|
||||
var contype,
|
||||
fieldname,
|
||||
parsed,
|
||||
charset,
|
||||
encoding,
|
||||
filename,
|
||||
nsize = 0;
|
||||
|
||||
if (header['content-type']) {
|
||||
parsed = parseParams(header['content-type'][0]);
|
||||
if (parsed[0]) {
|
||||
contype = parsed[0].toLowerCase();
|
||||
for (i = 0, len = parsed.length; i < len; ++i) {
|
||||
if (RE_CHARSET.test(parsed[i][0])) {
|
||||
charset = parsed[i][1].toLowerCase();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (contype === undefined)
|
||||
contype = 'text/plain';
|
||||
if (charset === undefined)
|
||||
charset = defCharset;
|
||||
|
||||
if (header['content-disposition']) {
|
||||
parsed = parseParams(header['content-disposition'][0]);
|
||||
if (!RE_FIELD.test(parsed[0]))
|
||||
return skipPart(part);
|
||||
for (i = 0, len = parsed.length; i < len; ++i) {
|
||||
if (RE_NAME.test(parsed[i][0])) {
|
||||
fieldname = decodeText(parsed[i][1], 'binary', 'utf8');
|
||||
} else if (RE_FILENAME.test(parsed[i][0])) {
|
||||
filename = decodeText(parsed[i][1], 'binary', 'utf8');
|
||||
if (!preservePath)
|
||||
filename = basename(filename);
|
||||
}
|
||||
}
|
||||
} else
|
||||
return skipPart(part);
|
||||
|
||||
if (header['content-transfer-encoding'])
|
||||
encoding = header['content-transfer-encoding'][0].toLowerCase();
|
||||
else
|
||||
encoding = '7bit';
|
||||
|
||||
var onData,
|
||||
onEnd;
|
||||
if (contype === 'application/octet-stream' || filename !== undefined) {
|
||||
// file/binary field
|
||||
if (nfiles === filesLimit) {
|
||||
if (!boy.hitFilesLimit) {
|
||||
boy.hitFilesLimit = true;
|
||||
boy.emit('filesLimit');
|
||||
}
|
||||
return skipPart(part);
|
||||
}
|
||||
|
||||
++nfiles;
|
||||
|
||||
if (!boy._events.file) {
|
||||
self.parser._ignore();
|
||||
return;
|
||||
}
|
||||
|
||||
++nends;
|
||||
var file = new FileStream(fileopts);
|
||||
curFile = file;
|
||||
file.on('end', function() {
|
||||
--nends;
|
||||
checkFinished();
|
||||
if (self._cb && !self._needDrain) {
|
||||
var cb = self._cb;
|
||||
self._cb = undefined;
|
||||
cb();
|
||||
}
|
||||
});
|
||||
file._read = function(n) {
|
||||
if (!self._pause)
|
||||
return;
|
||||
self._pause = false;
|
||||
if (self._cb && !self._needDrain) {
|
||||
var cb = self._cb;
|
||||
self._cb = undefined;
|
||||
cb();
|
||||
}
|
||||
};
|
||||
boy.emit('file', fieldname, file, filename, encoding, contype);
|
||||
|
||||
onData = function(data) {
|
||||
if ((nsize += data.length) > fileSizeLimit) {
|
||||
var extralen = (fileSizeLimit - (nsize - data.length));
|
||||
if (extralen > 0)
|
||||
file.push(data.slice(0, extralen));
|
||||
file.emit('limit');
|
||||
file.truncated = true;
|
||||
part.removeAllListeners('data');
|
||||
} else if (!file.push(data))
|
||||
self._pause = true;
|
||||
};
|
||||
|
||||
onEnd = function() {
|
||||
curFile = undefined;
|
||||
file.push(null);
|
||||
};
|
||||
} else {
|
||||
// non-file field
|
||||
if (nfields === fieldsLimit) {
|
||||
if (!boy.hitFieldsLimit) {
|
||||
boy.hitFieldsLimit = true;
|
||||
boy.emit('fieldsLimit');
|
||||
}
|
||||
return skipPart(part);
|
||||
}
|
||||
|
||||
++nfields;
|
||||
++nends;
|
||||
var buffer = '',
|
||||
truncated = false;
|
||||
curField = part;
|
||||
|
||||
onData = function(data) {
|
||||
if ((nsize += data.length) > fieldSizeLimit) {
|
||||
var extralen = (fieldSizeLimit - (nsize - data.length));
|
||||
buffer += data.toString('binary', 0, extralen);
|
||||
truncated = true;
|
||||
part.removeAllListeners('data');
|
||||
} else
|
||||
buffer += data.toString('binary');
|
||||
};
|
||||
|
||||
onEnd = function() {
|
||||
curField = undefined;
|
||||
if (buffer.length)
|
||||
buffer = decodeText(buffer, 'binary', charset);
|
||||
boy.emit('field', fieldname, buffer, false, truncated, encoding, contype);
|
||||
--nends;
|
||||
checkFinished();
|
||||
};
|
||||
}
|
||||
|
||||
/* As of node@2efe4ab761666 (v0.10.29+/v0.11.14+), busboy had become
|
||||
broken. Streams2/streams3 is a huge black box of confusion, but
|
||||
somehow overriding the sync state seems to fix things again (and still
|
||||
seems to work for previous node versions).
|
||||
*/
|
||||
part._readableState.sync = false;
|
||||
|
||||
part.on('data', onData);
|
||||
part.on('end', onEnd);
|
||||
}).on('error', function(err) {
|
||||
if (curFile)
|
||||
curFile.emit('error', err);
|
||||
});
|
||||
}).on('error', function(err) {
|
||||
boy.emit('error', err);
|
||||
}).on('finish', function() {
|
||||
finished = true;
|
||||
checkFinished();
|
||||
});
|
||||
}
|
||||
|
||||
Multipart.prototype.write = function(chunk, cb) {
|
||||
var r;
|
||||
if ((r = this.parser.write(chunk)) && !this._pause)
|
||||
cb();
|
||||
else {
|
||||
this._needDrain = !r;
|
||||
this._cb = cb;
|
||||
}
|
||||
};
|
||||
|
||||
Multipart.prototype.end = function() {
|
||||
var self = this;
|
||||
if (this._nparts === 0 && !self._boy._done) {
|
||||
process.nextTick(function() {
|
||||
self._boy._done = true;
|
||||
self._boy.emit('finish');
|
||||
});
|
||||
} else if (this.parser.writable)
|
||||
this.parser.end();
|
||||
};
|
||||
|
||||
function skipPart(part) {
|
||||
part.resume();
|
||||
}
|
||||
|
||||
function FileStream(opts) {
|
||||
if (!(this instanceof FileStream))
|
||||
return new FileStream(opts);
|
||||
ReadableStream.call(this, opts);
|
||||
|
||||
this.truncated = false;
|
||||
}
|
||||
inherits(FileStream, ReadableStream);
|
||||
|
||||
FileStream.prototype._read = function(n) {};
|
||||
|
||||
module.exports = Multipart;
|
214
express-server/node_modules/busboy/lib/types/urlencoded.js
generated
vendored
Normal file
214
express-server/node_modules/busboy/lib/types/urlencoded.js
generated
vendored
Normal file
@ -0,0 +1,214 @@
|
||||
var Decoder = require('../utils').Decoder,
|
||||
decodeText = require('../utils').decodeText;
|
||||
|
||||
var RE_CHARSET = /^charset$/i;
|
||||
|
||||
UrlEncoded.detect = /^application\/x-www-form-urlencoded/i;
|
||||
function UrlEncoded(boy, cfg) {
|
||||
if (!(this instanceof UrlEncoded))
|
||||
return new UrlEncoded(boy, cfg);
|
||||
var limits = cfg.limits,
|
||||
headers = cfg.headers,
|
||||
parsedConType = cfg.parsedConType;
|
||||
this.boy = boy;
|
||||
|
||||
this.fieldSizeLimit = (limits && typeof limits.fieldSize === 'number'
|
||||
? limits.fieldSize
|
||||
: 1 * 1024 * 1024);
|
||||
this.fieldNameSizeLimit = (limits && typeof limits.fieldNameSize === 'number'
|
||||
? limits.fieldNameSize
|
||||
: 100);
|
||||
this.fieldsLimit = (limits && typeof limits.fields === 'number'
|
||||
? limits.fields
|
||||
: Infinity);
|
||||
|
||||
var charset;
|
||||
for (var i = 0, len = parsedConType.length; i < len; ++i) {
|
||||
if (Array.isArray(parsedConType[i])
|
||||
&& RE_CHARSET.test(parsedConType[i][0])) {
|
||||
charset = parsedConType[i][1].toLowerCase();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (charset === undefined)
|
||||
charset = cfg.defCharset || 'utf8';
|
||||
|
||||
this.decoder = new Decoder();
|
||||
this.charset = charset;
|
||||
this._fields = 0;
|
||||
this._state = 'key';
|
||||
this._checkingBytes = true;
|
||||
this._bytesKey = 0;
|
||||
this._bytesVal = 0;
|
||||
this._key = '';
|
||||
this._val = '';
|
||||
this._keyTrunc = false;
|
||||
this._valTrunc = false;
|
||||
this._hitlimit = false;
|
||||
}
|
||||
|
||||
UrlEncoded.prototype.write = function(data, cb) {
|
||||
if (this._fields === this.fieldsLimit) {
|
||||
if (!this.boy.hitFieldsLimit) {
|
||||
this.boy.hitFieldsLimit = true;
|
||||
this.boy.emit('fieldsLimit');
|
||||
}
|
||||
return cb();
|
||||
}
|
||||
|
||||
var idxeq, idxamp, i, p = 0, len = data.length;
|
||||
|
||||
while (p < len) {
|
||||
if (this._state === 'key') {
|
||||
idxeq = idxamp = undefined;
|
||||
for (i = p; i < len; ++i) {
|
||||
if (!this._checkingBytes)
|
||||
++p;
|
||||
if (data[i] === 0x3D/*=*/) {
|
||||
idxeq = i;
|
||||
break;
|
||||
} else if (data[i] === 0x26/*&*/) {
|
||||
idxamp = i;
|
||||
break;
|
||||
}
|
||||
if (this._checkingBytes && this._bytesKey === this.fieldNameSizeLimit) {
|
||||
this._hitLimit = true;
|
||||
break;
|
||||
} else if (this._checkingBytes)
|
||||
++this._bytesKey;
|
||||
}
|
||||
|
||||
if (idxeq !== undefined) {
|
||||
// key with assignment
|
||||
if (idxeq > p)
|
||||
this._key += this.decoder.write(data.toString('binary', p, idxeq));
|
||||
this._state = 'val';
|
||||
|
||||
this._hitLimit = false;
|
||||
this._checkingBytes = true;
|
||||
this._val = '';
|
||||
this._bytesVal = 0;
|
||||
this._valTrunc = false;
|
||||
this.decoder.reset();
|
||||
|
||||
p = idxeq + 1;
|
||||
} else if (idxamp !== undefined) {
|
||||
// key with no assignment
|
||||
++this._fields;
|
||||
var key, keyTrunc = this._keyTrunc;
|
||||
if (idxamp > p)
|
||||
key = (this._key += this.decoder.write(data.toString('binary', p, idxamp)));
|
||||
else
|
||||
key = this._key;
|
||||
|
||||
this._hitLimit = false;
|
||||
this._checkingBytes = true;
|
||||
this._key = '';
|
||||
this._bytesKey = 0;
|
||||
this._keyTrunc = false;
|
||||
this.decoder.reset();
|
||||
|
||||
if (key.length) {
|
||||
this.boy.emit('field', decodeText(key, 'binary', this.charset),
|
||||
'',
|
||||
keyTrunc,
|
||||
false);
|
||||
}
|
||||
|
||||
p = idxamp + 1;
|
||||
if (this._fields === this.fieldsLimit)
|
||||
return cb();
|
||||
} else if (this._hitLimit) {
|
||||
// we may not have hit the actual limit if there are encoded bytes...
|
||||
if (i > p)
|
||||
this._key += this.decoder.write(data.toString('binary', p, i));
|
||||
p = i;
|
||||
if ((this._bytesKey = this._key.length) === this.fieldNameSizeLimit) {
|
||||
// yep, we actually did hit the limit
|
||||
this._checkingBytes = false;
|
||||
this._keyTrunc = true;
|
||||
}
|
||||
} else {
|
||||
if (p < len)
|
||||
this._key += this.decoder.write(data.toString('binary', p));
|
||||
p = len;
|
||||
}
|
||||
} else {
|
||||
idxamp = undefined;
|
||||
for (i = p; i < len; ++i) {
|
||||
if (!this._checkingBytes)
|
||||
++p;
|
||||
if (data[i] === 0x26/*&*/) {
|
||||
idxamp = i;
|
||||
break;
|
||||
}
|
||||
if (this._checkingBytes && this._bytesVal === this.fieldSizeLimit) {
|
||||
this._hitLimit = true;
|
||||
break;
|
||||
}
|
||||
else if (this._checkingBytes)
|
||||
++this._bytesVal;
|
||||
}
|
||||
|
||||
if (idxamp !== undefined) {
|
||||
++this._fields;
|
||||
if (idxamp > p)
|
||||
this._val += this.decoder.write(data.toString('binary', p, idxamp));
|
||||
this.boy.emit('field', decodeText(this._key, 'binary', this.charset),
|
||||
decodeText(this._val, 'binary', this.charset),
|
||||
this._keyTrunc,
|
||||
this._valTrunc);
|
||||
this._state = 'key';
|
||||
|
||||
this._hitLimit = false;
|
||||
this._checkingBytes = true;
|
||||
this._key = '';
|
||||
this._bytesKey = 0;
|
||||
this._keyTrunc = false;
|
||||
this.decoder.reset();
|
||||
|
||||
p = idxamp + 1;
|
||||
if (this._fields === this.fieldsLimit)
|
||||
return cb();
|
||||
} else if (this._hitLimit) {
|
||||
// we may not have hit the actual limit if there are encoded bytes...
|
||||
if (i > p)
|
||||
this._val += this.decoder.write(data.toString('binary', p, i));
|
||||
p = i;
|
||||
if ((this._val === '' && this.fieldSizeLimit === 0)
|
||||
|| (this._bytesVal = this._val.length) === this.fieldSizeLimit) {
|
||||
// yep, we actually did hit the limit
|
||||
this._checkingBytes = false;
|
||||
this._valTrunc = true;
|
||||
}
|
||||
} else {
|
||||
if (p < len)
|
||||
this._val += this.decoder.write(data.toString('binary', p));
|
||||
p = len;
|
||||
}
|
||||
}
|
||||
}
|
||||
cb();
|
||||
};
|
||||
|
||||
UrlEncoded.prototype.end = function() {
|
||||
if (this.boy._done)
|
||||
return;
|
||||
|
||||
if (this._state === 'key' && this._key.length > 0) {
|
||||
this.boy.emit('field', decodeText(this._key, 'binary', this.charset),
|
||||
'',
|
||||
this._keyTrunc,
|
||||
false);
|
||||
} else if (this._state === 'val') {
|
||||
this.boy.emit('field', decodeText(this._key, 'binary', this.charset),
|
||||
decodeText(this._val, 'binary', this.charset),
|
||||
this._keyTrunc,
|
||||
this._valTrunc);
|
||||
}
|
||||
this.boy._done = true;
|
||||
this.boy.emit('finish');
|
||||
};
|
||||
|
||||
module.exports = UrlEncoded;
|
186
express-server/node_modules/busboy/lib/utils.js
generated
vendored
Normal file
186
express-server/node_modules/busboy/lib/utils.js
generated
vendored
Normal file
@ -0,0 +1,186 @@
|
||||
var jsencoding = require('../deps/encoding/encoding');
|
||||
|
||||
var RE_ENCODED = /%([a-fA-F0-9]{2})/g;
|
||||
function encodedReplacer(match, byte) {
|
||||
return String.fromCharCode(parseInt(byte, 16));
|
||||
}
|
||||
function parseParams(str) {
|
||||
var res = [],
|
||||
state = 'key',
|
||||
charset = '',
|
||||
inquote = false,
|
||||
escaping = false,
|
||||
p = 0,
|
||||
tmp = '';
|
||||
|
||||
for (var i = 0, len = str.length; i < len; ++i) {
|
||||
if (str[i] === '\\' && inquote) {
|
||||
if (escaping)
|
||||
escaping = false;
|
||||
else {
|
||||
escaping = true;
|
||||
continue;
|
||||
}
|
||||
} else if (str[i] === '"') {
|
||||
if (!escaping) {
|
||||
if (inquote) {
|
||||
inquote = false;
|
||||
state = 'key';
|
||||
} else
|
||||
inquote = true;
|
||||
continue;
|
||||
} else
|
||||
escaping = false;
|
||||
} else {
|
||||
if (escaping && inquote)
|
||||
tmp += '\\';
|
||||
escaping = false;
|
||||
if ((state === 'charset' || state === 'lang') && str[i] === "'") {
|
||||
if (state === 'charset') {
|
||||
state = 'lang';
|
||||
charset = tmp.substring(1);
|
||||
} else
|
||||
state = 'value';
|
||||
tmp = '';
|
||||
continue;
|
||||
} else if (state === 'key'
|
||||
&& (str[i] === '*' || str[i] === '=')
|
||||
&& res.length) {
|
||||
if (str[i] === '*')
|
||||
state = 'charset';
|
||||
else
|
||||
state = 'value';
|
||||
res[p] = [tmp, undefined];
|
||||
tmp = '';
|
||||
continue;
|
||||
} else if (!inquote && str[i] === ';') {
|
||||
state = 'key';
|
||||
if (charset) {
|
||||
if (tmp.length) {
|
||||
tmp = decodeText(tmp.replace(RE_ENCODED, encodedReplacer),
|
||||
'binary',
|
||||
charset);
|
||||
}
|
||||
charset = '';
|
||||
}
|
||||
if (res[p] === undefined)
|
||||
res[p] = tmp;
|
||||
else
|
||||
res[p][1] = tmp;
|
||||
tmp = '';
|
||||
++p;
|
||||
continue;
|
||||
} else if (!inquote && (str[i] === ' ' || str[i] === '\t'))
|
||||
continue;
|
||||
}
|
||||
tmp += str[i];
|
||||
}
|
||||
if (charset && tmp.length) {
|
||||
tmp = decodeText(tmp.replace(RE_ENCODED, encodedReplacer),
|
||||
'binary',
|
||||
charset);
|
||||
}
|
||||
|
||||
if (res[p] === undefined) {
|
||||
if (tmp)
|
||||
res[p] = tmp;
|
||||
} else
|
||||
res[p][1] = tmp;
|
||||
|
||||
return res;
|
||||
};
|
||||
exports.parseParams = parseParams;
|
||||
|
||||
|
||||
function decodeText(text, textEncoding, destEncoding) {
|
||||
var ret;
|
||||
if (text && jsencoding.encodingExists(destEncoding)) {
|
||||
try {
|
||||
ret = jsencoding.TextDecoder(destEncoding)
|
||||
.decode(new Buffer(text, textEncoding));
|
||||
} catch(e) {}
|
||||
}
|
||||
return (typeof ret === 'string' ? ret : text);
|
||||
}
|
||||
exports.decodeText = decodeText;
|
||||
|
||||
|
||||
var HEX = [
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
|
||||
0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
], RE_PLUS = /\+/g;
|
||||
function Decoder() {
|
||||
this.buffer = undefined;
|
||||
}
|
||||
Decoder.prototype.write = function(str) {
|
||||
// Replace '+' with ' ' before decoding
|
||||
str = str.replace(RE_PLUS, ' ');
|
||||
var res = '';
|
||||
var i = 0, p = 0, len = str.length;
|
||||
for (; i < len; ++i) {
|
||||
if (this.buffer !== undefined) {
|
||||
if (!HEX[str.charCodeAt(i)]) {
|
||||
res += '%' + this.buffer;
|
||||
this.buffer = undefined;
|
||||
--i; // retry character
|
||||
} else {
|
||||
this.buffer += str[i];
|
||||
++p;
|
||||
if (this.buffer.length === 2) {
|
||||
res += String.fromCharCode(parseInt(this.buffer, 16));
|
||||
this.buffer = undefined;
|
||||
}
|
||||
}
|
||||
} else if (str[i] === '%') {
|
||||
if (i > p) {
|
||||
res += str.substring(p, i);
|
||||
p = i;
|
||||
}
|
||||
this.buffer = '';
|
||||
++p;
|
||||
}
|
||||
}
|
||||
if (p < len && this.buffer === undefined)
|
||||
res += str.substring(p);
|
||||
return res;
|
||||
};
|
||||
Decoder.prototype.reset = function() {
|
||||
this.buffer = undefined;
|
||||
};
|
||||
exports.Decoder = Decoder;
|
||||
|
||||
|
||||
var RE_SPLIT_POSIX =
|
||||
/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/,
|
||||
RE_SPLIT_DEVICE =
|
||||
/^([a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/]+[^\\\/]+)?([\\\/])?([\s\S]*?)$/,
|
||||
RE_SPLIT_WINDOWS =
|
||||
/^([\s\S]*?)((?:\.{1,2}|[^\\\/]+?|)(\.[^.\/\\]*|))(?:[\\\/]*)$/;
|
||||
function splitPathPosix(filename) {
|
||||
return RE_SPLIT_POSIX.exec(filename).slice(1);
|
||||
}
|
||||
function splitPathWindows(filename) {
|
||||
// Separate device+slash from tail
|
||||
var result = RE_SPLIT_DEVICE.exec(filename),
|
||||
device = (result[1] || '') + (result[2] || ''),
|
||||
tail = result[3] || '';
|
||||
// Split the tail into dir, basename and extension
|
||||
var result2 = RE_SPLIT_WINDOWS.exec(tail),
|
||||
dir = result2[1],
|
||||
basename = result2[2],
|
||||
ext = result2[3];
|
||||
return [device, dir, basename, ext];
|
||||
}
|
||||
function basename(path) {
|
||||
var f = splitPathPosix(path)[2];
|
||||
if (f === path)
|
||||
f = splitPathWindows(path)[2];
|
||||
return f;
|
||||
}
|
||||
exports.basename = basename;
|
5
express-server/node_modules/busboy/node_modules/readable-stream/.npmignore
generated
vendored
Normal file
5
express-server/node_modules/busboy/node_modules/readable-stream/.npmignore
generated
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
build/
|
||||
test/
|
||||
examples/
|
||||
fs.js
|
||||
zlib.js
|
18
express-server/node_modules/busboy/node_modules/readable-stream/LICENSE
generated
vendored
Normal file
18
express-server/node_modules/busboy/node_modules/readable-stream/LICENSE
generated
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
Copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
||||
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.
|
15
express-server/node_modules/busboy/node_modules/readable-stream/README.md
generated
vendored
Normal file
15
express-server/node_modules/busboy/node_modules/readable-stream/README.md
generated
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
# readable-stream
|
||||
|
||||
***Node-core streams for userland***
|
||||
|
||||
[](https://nodei.co/npm/readable-stream/)
|
||||
[](https://nodei.co/npm/readable-stream/)
|
||||
|
||||
This package is a mirror of the Streams2 and Streams3 implementations in Node-core.
|
||||
|
||||
If you want to guarantee a stable streams base, regardless of what version of Node you, or the users of your libraries are using, use **readable-stream** *only* and avoid the *"stream"* module in Node-core.
|
||||
|
||||
**readable-stream** comes in two major versions, v1.0.x and v1.1.x. The former tracks the Streams2 implementation in Node 0.10, including bug-fixes and minor improvements as they are added. The latter tracks Streams3 as it develops in Node 0.11; we will likely see a v1.2.x branch for Node 0.12.
|
||||
|
||||
**readable-stream** uses proper patch-level versioning so if you pin to `"~1.0.0"` you’ll get the latest Node 0.10 Streams2 implementation, including any fixes and minor non-breaking improvements. The patch-level versions of 1.0.x and 1.1.x should mirror the patch-level versions of Node-core releases. You should prefer the **1.0.x** releases for now and when you’re ready to start using Streams3, pin to `"~1.1.0"`
|
||||
|
1
express-server/node_modules/busboy/node_modules/readable-stream/duplex.js
generated
vendored
Normal file
1
express-server/node_modules/busboy/node_modules/readable-stream/duplex.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
module.exports = require("./lib/_stream_duplex.js")
|
923
express-server/node_modules/busboy/node_modules/readable-stream/float.patch
generated
vendored
Normal file
923
express-server/node_modules/busboy/node_modules/readable-stream/float.patch
generated
vendored
Normal file
@ -0,0 +1,923 @@
|
||||
diff --git a/lib/_stream_duplex.js b/lib/_stream_duplex.js
|
||||
index c5a741c..a2e0d8e 100644
|
||||
--- a/lib/_stream_duplex.js
|
||||
+++ b/lib/_stream_duplex.js
|
||||
@@ -26,8 +26,8 @@
|
||||
|
||||
module.exports = Duplex;
|
||||
var util = require('util');
|
||||
-var Readable = require('_stream_readable');
|
||||
-var Writable = require('_stream_writable');
|
||||
+var Readable = require('./_stream_readable');
|
||||
+var Writable = require('./_stream_writable');
|
||||
|
||||
util.inherits(Duplex, Readable);
|
||||
|
||||
diff --git a/lib/_stream_passthrough.js b/lib/_stream_passthrough.js
|
||||
index a5e9864..330c247 100644
|
||||
--- a/lib/_stream_passthrough.js
|
||||
+++ b/lib/_stream_passthrough.js
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
module.exports = PassThrough;
|
||||
|
||||
-var Transform = require('_stream_transform');
|
||||
+var Transform = require('./_stream_transform');
|
||||
var util = require('util');
|
||||
util.inherits(PassThrough, Transform);
|
||||
|
||||
diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js
|
||||
index 0c3fe3e..90a8298 100644
|
||||
--- a/lib/_stream_readable.js
|
||||
+++ b/lib/_stream_readable.js
|
||||
@@ -23,10 +23,34 @@ module.exports = Readable;
|
||||
Readable.ReadableState = ReadableState;
|
||||
|
||||
var EE = require('events').EventEmitter;
|
||||
+if (!EE.listenerCount) EE.listenerCount = function(emitter, type) {
|
||||
+ return emitter.listeners(type).length;
|
||||
+};
|
||||
+
|
||||
+if (!global.setImmediate) global.setImmediate = function setImmediate(fn) {
|
||||
+ return setTimeout(fn, 0);
|
||||
+};
|
||||
+if (!global.clearImmediate) global.clearImmediate = function clearImmediate(i) {
|
||||
+ return clearTimeout(i);
|
||||
+};
|
||||
+
|
||||
var Stream = require('stream');
|
||||
var util = require('util');
|
||||
+if (!util.isUndefined) {
|
||||
+ var utilIs = require('core-util-is');
|
||||
+ for (var f in utilIs) {
|
||||
+ util[f] = utilIs[f];
|
||||
+ }
|
||||
+}
|
||||
var StringDecoder;
|
||||
-var debug = util.debuglog('stream');
|
||||
+var debug;
|
||||
+if (util.debuglog)
|
||||
+ debug = util.debuglog('stream');
|
||||
+else try {
|
||||
+ debug = require('debuglog')('stream');
|
||||
+} catch (er) {
|
||||
+ debug = function() {};
|
||||
+}
|
||||
|
||||
util.inherits(Readable, Stream);
|
||||
|
||||
@@ -380,7 +404,7 @@ function chunkInvalid(state, chunk) {
|
||||
|
||||
|
||||
function onEofChunk(stream, state) {
|
||||
- if (state.decoder && !state.ended) {
|
||||
+ if (state.decoder && !state.ended && state.decoder.end) {
|
||||
var chunk = state.decoder.end();
|
||||
if (chunk && chunk.length) {
|
||||
state.buffer.push(chunk);
|
||||
diff --git a/lib/_stream_transform.js b/lib/_stream_transform.js
|
||||
index b1f9fcc..b0caf57 100644
|
||||
--- a/lib/_stream_transform.js
|
||||
+++ b/lib/_stream_transform.js
|
||||
@@ -64,8 +64,14 @@
|
||||
|
||||
module.exports = Transform;
|
||||
|
||||
-var Duplex = require('_stream_duplex');
|
||||
+var Duplex = require('./_stream_duplex');
|
||||
var util = require('util');
|
||||
+if (!util.isUndefined) {
|
||||
+ var utilIs = require('core-util-is');
|
||||
+ for (var f in utilIs) {
|
||||
+ util[f] = utilIs[f];
|
||||
+ }
|
||||
+}
|
||||
util.inherits(Transform, Duplex);
|
||||
|
||||
|
||||
diff --git a/lib/_stream_writable.js b/lib/_stream_writable.js
|
||||
index ba2e920..f49288b 100644
|
||||
--- a/lib/_stream_writable.js
|
||||
+++ b/lib/_stream_writable.js
|
||||
@@ -27,6 +27,12 @@ module.exports = Writable;
|
||||
Writable.WritableState = WritableState;
|
||||
|
||||
var util = require('util');
|
||||
+if (!util.isUndefined) {
|
||||
+ var utilIs = require('core-util-is');
|
||||
+ for (var f in utilIs) {
|
||||
+ util[f] = utilIs[f];
|
||||
+ }
|
||||
+}
|
||||
var Stream = require('stream');
|
||||
|
||||
util.inherits(Writable, Stream);
|
||||
@@ -119,7 +125,7 @@ function WritableState(options, stream) {
|
||||
function Writable(options) {
|
||||
// Writable ctor is applied to Duplexes, though they're not
|
||||
// instanceof Writable, they're instanceof Readable.
|
||||
- if (!(this instanceof Writable) && !(this instanceof Stream.Duplex))
|
||||
+ if (!(this instanceof Writable) && !(this instanceof require('./_stream_duplex')))
|
||||
return new Writable(options);
|
||||
|
||||
this._writableState = new WritableState(options, this);
|
||||
diff --git a/test/simple/test-stream-big-push.js b/test/simple/test-stream-big-push.js
|
||||
index e3787e4..8cd2127 100644
|
||||
--- a/test/simple/test-stream-big-push.js
|
||||
+++ b/test/simple/test-stream-big-push.js
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
var common = require('../common');
|
||||
var assert = require('assert');
|
||||
-var stream = require('stream');
|
||||
+var stream = require('../../');
|
||||
var str = 'asdfasdfasdfasdfasdf';
|
||||
|
||||
var r = new stream.Readable({
|
||||
diff --git a/test/simple/test-stream-end-paused.js b/test/simple/test-stream-end-paused.js
|
||||
index bb73777..d40efc7 100644
|
||||
--- a/test/simple/test-stream-end-paused.js
|
||||
+++ b/test/simple/test-stream-end-paused.js
|
||||
@@ -25,7 +25,7 @@ var gotEnd = false;
|
||||
|
||||
// Make sure we don't miss the end event for paused 0-length streams
|
||||
|
||||
-var Readable = require('stream').Readable;
|
||||
+var Readable = require('../../').Readable;
|
||||
var stream = new Readable();
|
||||
var calledRead = false;
|
||||
stream._read = function() {
|
||||
diff --git a/test/simple/test-stream-pipe-after-end.js b/test/simple/test-stream-pipe-after-end.js
|
||||
index b46ee90..0be8366 100644
|
||||
--- a/test/simple/test-stream-pipe-after-end.js
|
||||
+++ b/test/simple/test-stream-pipe-after-end.js
|
||||
@@ -22,8 +22,8 @@
|
||||
var common = require('../common');
|
||||
var assert = require('assert');
|
||||
|
||||
-var Readable = require('_stream_readable');
|
||||
-var Writable = require('_stream_writable');
|
||||
+var Readable = require('../../lib/_stream_readable');
|
||||
+var Writable = require('../../lib/_stream_writable');
|
||||
var util = require('util');
|
||||
|
||||
util.inherits(TestReadable, Readable);
|
||||
diff --git a/test/simple/test-stream-pipe-cleanup.js b/test/simple/test-stream-pipe-cleanup.js
|
||||
deleted file mode 100644
|
||||
index f689358..0000000
|
||||
--- a/test/simple/test-stream-pipe-cleanup.js
|
||||
+++ /dev/null
|
||||
@@ -1,122 +0,0 @@
|
||||
-// Copyright Joyent, Inc. and other Node contributors.
|
||||
-//
|
||||
-// 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.
|
||||
-
|
||||
-// This test asserts that Stream.prototype.pipe does not leave listeners
|
||||
-// hanging on the source or dest.
|
||||
-
|
||||
-var common = require('../common');
|
||||
-var stream = require('stream');
|
||||
-var assert = require('assert');
|
||||
-var util = require('util');
|
||||
-
|
||||
-function Writable() {
|
||||
- this.writable = true;
|
||||
- this.endCalls = 0;
|
||||
- stream.Stream.call(this);
|
||||
-}
|
||||
-util.inherits(Writable, stream.Stream);
|
||||
-Writable.prototype.end = function() {
|
||||
- this.endCalls++;
|
||||
-};
|
||||
-
|
||||
-Writable.prototype.destroy = function() {
|
||||
- this.endCalls++;
|
||||
-};
|
||||
-
|
||||
-function Readable() {
|
||||
- this.readable = true;
|
||||
- stream.Stream.call(this);
|
||||
-}
|
||||
-util.inherits(Readable, stream.Stream);
|
||||
-
|
||||
-function Duplex() {
|
||||
- this.readable = true;
|
||||
- Writable.call(this);
|
||||
-}
|
||||
-util.inherits(Duplex, Writable);
|
||||
-
|
||||
-var i = 0;
|
||||
-var limit = 100;
|
||||
-
|
||||
-var w = new Writable();
|
||||
-
|
||||
-var r;
|
||||
-
|
||||
-for (i = 0; i < limit; i++) {
|
||||
- r = new Readable();
|
||||
- r.pipe(w);
|
||||
- r.emit('end');
|
||||
-}
|
||||
-assert.equal(0, r.listeners('end').length);
|
||||
-assert.equal(limit, w.endCalls);
|
||||
-
|
||||
-w.endCalls = 0;
|
||||
-
|
||||
-for (i = 0; i < limit; i++) {
|
||||
- r = new Readable();
|
||||
- r.pipe(w);
|
||||
- r.emit('close');
|
||||
-}
|
||||
-assert.equal(0, r.listeners('close').length);
|
||||
-assert.equal(limit, w.endCalls);
|
||||
-
|
||||
-w.endCalls = 0;
|
||||
-
|
||||
-r = new Readable();
|
||||
-
|
||||
-for (i = 0; i < limit; i++) {
|
||||
- w = new Writable();
|
||||
- r.pipe(w);
|
||||
- w.emit('close');
|
||||
-}
|
||||
-assert.equal(0, w.listeners('close').length);
|
||||
-
|
||||
-r = new Readable();
|
||||
-w = new Writable();
|
||||
-var d = new Duplex();
|
||||
-r.pipe(d); // pipeline A
|
||||
-d.pipe(w); // pipeline B
|
||||
-assert.equal(r.listeners('end').length, 2); // A.onend, A.cleanup
|
||||
-assert.equal(r.listeners('close').length, 2); // A.onclose, A.cleanup
|
||||
-assert.equal(d.listeners('end').length, 2); // B.onend, B.cleanup
|
||||
-assert.equal(d.listeners('close').length, 3); // A.cleanup, B.onclose, B.cleanup
|
||||
-assert.equal(w.listeners('end').length, 0);
|
||||
-assert.equal(w.listeners('close').length, 1); // B.cleanup
|
||||
-
|
||||
-r.emit('end');
|
||||
-assert.equal(d.endCalls, 1);
|
||||
-assert.equal(w.endCalls, 0);
|
||||
-assert.equal(r.listeners('end').length, 0);
|
||||
-assert.equal(r.listeners('close').length, 0);
|
||||
-assert.equal(d.listeners('end').length, 2); // B.onend, B.cleanup
|
||||
-assert.equal(d.listeners('close').length, 2); // B.onclose, B.cleanup
|
||||
-assert.equal(w.listeners('end').length, 0);
|
||||
-assert.equal(w.listeners('close').length, 1); // B.cleanup
|
||||
-
|
||||
-d.emit('end');
|
||||
-assert.equal(d.endCalls, 1);
|
||||
-assert.equal(w.endCalls, 1);
|
||||
-assert.equal(r.listeners('end').length, 0);
|
||||
-assert.equal(r.listeners('close').length, 0);
|
||||
-assert.equal(d.listeners('end').length, 0);
|
||||
-assert.equal(d.listeners('close').length, 0);
|
||||
-assert.equal(w.listeners('end').length, 0);
|
||||
-assert.equal(w.listeners('close').length, 0);
|
||||
diff --git a/test/simple/test-stream-pipe-error-handling.js b/test/simple/test-stream-pipe-error-handling.js
|
||||
index c5d724b..c7d6b7d 100644
|
||||
--- a/test/simple/test-stream-pipe-error-handling.js
|
||||
+++ b/test/simple/test-stream-pipe-error-handling.js
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
var common = require('../common');
|
||||
var assert = require('assert');
|
||||
-var Stream = require('stream').Stream;
|
||||
+var Stream = require('../../').Stream;
|
||||
|
||||
(function testErrorListenerCatches() {
|
||||
var source = new Stream();
|
||||
diff --git a/test/simple/test-stream-pipe-event.js b/test/simple/test-stream-pipe-event.js
|
||||
index cb9d5fe..56f8d61 100644
|
||||
--- a/test/simple/test-stream-pipe-event.js
|
||||
+++ b/test/simple/test-stream-pipe-event.js
|
||||
@@ -20,7 +20,7 @@
|
||||
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
var common = require('../common');
|
||||
-var stream = require('stream');
|
||||
+var stream = require('../../');
|
||||
var assert = require('assert');
|
||||
var util = require('util');
|
||||
|
||||
diff --git a/test/simple/test-stream-push-order.js b/test/simple/test-stream-push-order.js
|
||||
index f2e6ec2..a5c9bf9 100644
|
||||
--- a/test/simple/test-stream-push-order.js
|
||||
+++ b/test/simple/test-stream-push-order.js
|
||||
@@ -20,7 +20,7 @@
|
||||
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
var common = require('../common.js');
|
||||
-var Readable = require('stream').Readable;
|
||||
+var Readable = require('../../').Readable;
|
||||
var assert = require('assert');
|
||||
|
||||
var s = new Readable({
|
||||
diff --git a/test/simple/test-stream-push-strings.js b/test/simple/test-stream-push-strings.js
|
||||
index 06f43dc..1701a9a 100644
|
||||
--- a/test/simple/test-stream-push-strings.js
|
||||
+++ b/test/simple/test-stream-push-strings.js
|
||||
@@ -22,7 +22,7 @@
|
||||
var common = require('../common');
|
||||
var assert = require('assert');
|
||||
|
||||
-var Readable = require('stream').Readable;
|
||||
+var Readable = require('../../').Readable;
|
||||
var util = require('util');
|
||||
|
||||
util.inherits(MyStream, Readable);
|
||||
diff --git a/test/simple/test-stream-readable-event.js b/test/simple/test-stream-readable-event.js
|
||||
index ba6a577..a8e6f7b 100644
|
||||
--- a/test/simple/test-stream-readable-event.js
|
||||
+++ b/test/simple/test-stream-readable-event.js
|
||||
@@ -22,7 +22,7 @@
|
||||
var common = require('../common');
|
||||
var assert = require('assert');
|
||||
|
||||
-var Readable = require('stream').Readable;
|
||||
+var Readable = require('../../').Readable;
|
||||
|
||||
(function first() {
|
||||
// First test, not reading when the readable is added.
|
||||
diff --git a/test/simple/test-stream-readable-flow-recursion.js b/test/simple/test-stream-readable-flow-recursion.js
|
||||
index 2891ad6..11689ba 100644
|
||||
--- a/test/simple/test-stream-readable-flow-recursion.js
|
||||
+++ b/test/simple/test-stream-readable-flow-recursion.js
|
||||
@@ -27,7 +27,7 @@ var assert = require('assert');
|
||||
// more data continuously, but without triggering a nextTick
|
||||
// warning or RangeError.
|
||||
|
||||
-var Readable = require('stream').Readable;
|
||||
+var Readable = require('../../').Readable;
|
||||
|
||||
// throw an error if we trigger a nextTick warning.
|
||||
process.throwDeprecation = true;
|
||||
diff --git a/test/simple/test-stream-unshift-empty-chunk.js b/test/simple/test-stream-unshift-empty-chunk.js
|
||||
index 0c96476..7827538 100644
|
||||
--- a/test/simple/test-stream-unshift-empty-chunk.js
|
||||
+++ b/test/simple/test-stream-unshift-empty-chunk.js
|
||||
@@ -24,7 +24,7 @@ var assert = require('assert');
|
||||
|
||||
// This test verifies that stream.unshift(Buffer(0)) or
|
||||
// stream.unshift('') does not set state.reading=false.
|
||||
-var Readable = require('stream').Readable;
|
||||
+var Readable = require('../../').Readable;
|
||||
|
||||
var r = new Readable();
|
||||
var nChunks = 10;
|
||||
diff --git a/test/simple/test-stream-unshift-read-race.js b/test/simple/test-stream-unshift-read-race.js
|
||||
index 83fd9fa..17c18aa 100644
|
||||
--- a/test/simple/test-stream-unshift-read-race.js
|
||||
+++ b/test/simple/test-stream-unshift-read-race.js
|
||||
@@ -29,7 +29,7 @@ var assert = require('assert');
|
||||
// 3. push() after the EOF signaling null is an error.
|
||||
// 4. _read() is not called after pushing the EOF null chunk.
|
||||
|
||||
-var stream = require('stream');
|
||||
+var stream = require('../../');
|
||||
var hwm = 10;
|
||||
var r = stream.Readable({ highWaterMark: hwm });
|
||||
var chunks = 10;
|
||||
@@ -51,7 +51,14 @@ r._read = function(n) {
|
||||
|
||||
function push(fast) {
|
||||
assert(!pushedNull, 'push() after null push');
|
||||
- var c = pos >= data.length ? null : data.slice(pos, pos + n);
|
||||
+ var c;
|
||||
+ if (pos >= data.length)
|
||||
+ c = null;
|
||||
+ else {
|
||||
+ if (n + pos > data.length)
|
||||
+ n = data.length - pos;
|
||||
+ c = data.slice(pos, pos + n);
|
||||
+ }
|
||||
pushedNull = c === null;
|
||||
if (fast) {
|
||||
pos += n;
|
||||
diff --git a/test/simple/test-stream-writev.js b/test/simple/test-stream-writev.js
|
||||
index 5b49e6e..b5321f3 100644
|
||||
--- a/test/simple/test-stream-writev.js
|
||||
+++ b/test/simple/test-stream-writev.js
|
||||
@@ -22,7 +22,7 @@
|
||||
var common = require('../common');
|
||||
var assert = require('assert');
|
||||
|
||||
-var stream = require('stream');
|
||||
+var stream = require('../../');
|
||||
|
||||
var queue = [];
|
||||
for (var decode = 0; decode < 2; decode++) {
|
||||
diff --git a/test/simple/test-stream2-basic.js b/test/simple/test-stream2-basic.js
|
||||
index 3814bf0..248c1be 100644
|
||||
--- a/test/simple/test-stream2-basic.js
|
||||
+++ b/test/simple/test-stream2-basic.js
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
|
||||
var common = require('../common.js');
|
||||
-var R = require('_stream_readable');
|
||||
+var R = require('../../lib/_stream_readable');
|
||||
var assert = require('assert');
|
||||
|
||||
var util = require('util');
|
||||
diff --git a/test/simple/test-stream2-compatibility.js b/test/simple/test-stream2-compatibility.js
|
||||
index 6cdd4e9..f0fa84b 100644
|
||||
--- a/test/simple/test-stream2-compatibility.js
|
||||
+++ b/test/simple/test-stream2-compatibility.js
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
|
||||
var common = require('../common.js');
|
||||
-var R = require('_stream_readable');
|
||||
+var R = require('../../lib/_stream_readable');
|
||||
var assert = require('assert');
|
||||
|
||||
var util = require('util');
|
||||
diff --git a/test/simple/test-stream2-finish-pipe.js b/test/simple/test-stream2-finish-pipe.js
|
||||
index 39b274f..006a19b 100644
|
||||
--- a/test/simple/test-stream2-finish-pipe.js
|
||||
+++ b/test/simple/test-stream2-finish-pipe.js
|
||||
@@ -20,7 +20,7 @@
|
||||
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
var common = require('../common.js');
|
||||
-var stream = require('stream');
|
||||
+var stream = require('../../');
|
||||
var Buffer = require('buffer').Buffer;
|
||||
|
||||
var r = new stream.Readable();
|
||||
diff --git a/test/simple/test-stream2-fs.js b/test/simple/test-stream2-fs.js
|
||||
deleted file mode 100644
|
||||
index e162406..0000000
|
||||
--- a/test/simple/test-stream2-fs.js
|
||||
+++ /dev/null
|
||||
@@ -1,72 +0,0 @@
|
||||
-// Copyright Joyent, Inc. and other Node contributors.
|
||||
-//
|
||||
-// 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.
|
||||
-
|
||||
-
|
||||
-var common = require('../common.js');
|
||||
-var R = require('_stream_readable');
|
||||
-var assert = require('assert');
|
||||
-
|
||||
-var fs = require('fs');
|
||||
-var FSReadable = fs.ReadStream;
|
||||
-
|
||||
-var path = require('path');
|
||||
-var file = path.resolve(common.fixturesDir, 'x1024.txt');
|
||||
-
|
||||
-var size = fs.statSync(file).size;
|
||||
-
|
||||
-var expectLengths = [1024];
|
||||
-
|
||||
-var util = require('util');
|
||||
-var Stream = require('stream');
|
||||
-
|
||||
-util.inherits(TestWriter, Stream);
|
||||
-
|
||||
-function TestWriter() {
|
||||
- Stream.apply(this);
|
||||
- this.buffer = [];
|
||||
- this.length = 0;
|
||||
-}
|
||||
-
|
||||
-TestWriter.prototype.write = function(c) {
|
||||
- this.buffer.push(c.toString());
|
||||
- this.length += c.length;
|
||||
- return true;
|
||||
-};
|
||||
-
|
||||
-TestWriter.prototype.end = function(c) {
|
||||
- if (c) this.buffer.push(c.toString());
|
||||
- this.emit('results', this.buffer);
|
||||
-}
|
||||
-
|
||||
-var r = new FSReadable(file);
|
||||
-var w = new TestWriter();
|
||||
-
|
||||
-w.on('results', function(res) {
|
||||
- console.error(res, w.length);
|
||||
- assert.equal(w.length, size);
|
||||
- var l = 0;
|
||||
- assert.deepEqual(res.map(function (c) {
|
||||
- return c.length;
|
||||
- }), expectLengths);
|
||||
- console.log('ok');
|
||||
-});
|
||||
-
|
||||
-r.pipe(w);
|
||||
diff --git a/test/simple/test-stream2-httpclient-response-end.js b/test/simple/test-stream2-httpclient-response-end.js
|
||||
deleted file mode 100644
|
||||
index 15cffc2..0000000
|
||||
--- a/test/simple/test-stream2-httpclient-response-end.js
|
||||
+++ /dev/null
|
||||
@@ -1,52 +0,0 @@
|
||||
-// Copyright Joyent, Inc. and other Node contributors.
|
||||
-//
|
||||
-// 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.
|
||||
-
|
||||
-var common = require('../common.js');
|
||||
-var assert = require('assert');
|
||||
-var http = require('http');
|
||||
-var msg = 'Hello';
|
||||
-var readable_event = false;
|
||||
-var end_event = false;
|
||||
-var server = http.createServer(function(req, res) {
|
||||
- res.writeHead(200, {'Content-Type': 'text/plain'});
|
||||
- res.end(msg);
|
||||
-}).listen(common.PORT, function() {
|
||||
- http.get({port: common.PORT}, function(res) {
|
||||
- var data = '';
|
||||
- res.on('readable', function() {
|
||||
- console.log('readable event');
|
||||
- readable_event = true;
|
||||
- data += res.read();
|
||||
- });
|
||||
- res.on('end', function() {
|
||||
- console.log('end event');
|
||||
- end_event = true;
|
||||
- assert.strictEqual(msg, data);
|
||||
- server.close();
|
||||
- });
|
||||
- });
|
||||
-});
|
||||
-
|
||||
-process.on('exit', function() {
|
||||
- assert(readable_event);
|
||||
- assert(end_event);
|
||||
-});
|
||||
-
|
||||
diff --git a/test/simple/test-stream2-large-read-stall.js b/test/simple/test-stream2-large-read-stall.js
|
||||
index 2fbfbca..667985b 100644
|
||||
--- a/test/simple/test-stream2-large-read-stall.js
|
||||
+++ b/test/simple/test-stream2-large-read-stall.js
|
||||
@@ -30,7 +30,7 @@ var PUSHSIZE = 20;
|
||||
var PUSHCOUNT = 1000;
|
||||
var HWM = 50;
|
||||
|
||||
-var Readable = require('stream').Readable;
|
||||
+var Readable = require('../../').Readable;
|
||||
var r = new Readable({
|
||||
highWaterMark: HWM
|
||||
});
|
||||
@@ -39,23 +39,23 @@ var rs = r._readableState;
|
||||
r._read = push;
|
||||
|
||||
r.on('readable', function() {
|
||||
- console.error('>> readable');
|
||||
+ //console.error('>> readable');
|
||||
do {
|
||||
- console.error(' > read(%d)', READSIZE);
|
||||
+ //console.error(' > read(%d)', READSIZE);
|
||||
var ret = r.read(READSIZE);
|
||||
- console.error(' < %j (%d remain)', ret && ret.length, rs.length);
|
||||
+ //console.error(' < %j (%d remain)', ret && ret.length, rs.length);
|
||||
} while (ret && ret.length === READSIZE);
|
||||
|
||||
- console.error('<< after read()',
|
||||
- ret && ret.length,
|
||||
- rs.needReadable,
|
||||
- rs.length);
|
||||
+ //console.error('<< after read()',
|
||||
+ // ret && ret.length,
|
||||
+ // rs.needReadable,
|
||||
+ // rs.length);
|
||||
});
|
||||
|
||||
var endEmitted = false;
|
||||
r.on('end', function() {
|
||||
endEmitted = true;
|
||||
- console.error('end');
|
||||
+ //console.error('end');
|
||||
});
|
||||
|
||||
var pushes = 0;
|
||||
@@ -64,11 +64,11 @@ function push() {
|
||||
return;
|
||||
|
||||
if (pushes++ === PUSHCOUNT) {
|
||||
- console.error(' push(EOF)');
|
||||
+ //console.error(' push(EOF)');
|
||||
return r.push(null);
|
||||
}
|
||||
|
||||
- console.error(' push #%d', pushes);
|
||||
+ //console.error(' push #%d', pushes);
|
||||
if (r.push(new Buffer(PUSHSIZE)))
|
||||
setTimeout(push);
|
||||
}
|
||||
diff --git a/test/simple/test-stream2-objects.js b/test/simple/test-stream2-objects.js
|
||||
index 3e6931d..ff47d89 100644
|
||||
--- a/test/simple/test-stream2-objects.js
|
||||
+++ b/test/simple/test-stream2-objects.js
|
||||
@@ -21,8 +21,8 @@
|
||||
|
||||
|
||||
var common = require('../common.js');
|
||||
-var Readable = require('_stream_readable');
|
||||
-var Writable = require('_stream_writable');
|
||||
+var Readable = require('../../lib/_stream_readable');
|
||||
+var Writable = require('../../lib/_stream_writable');
|
||||
var assert = require('assert');
|
||||
|
||||
// tiny node-tap lookalike.
|
||||
diff --git a/test/simple/test-stream2-pipe-error-handling.js b/test/simple/test-stream2-pipe-error-handling.js
|
||||
index cf7531c..e3f3e4e 100644
|
||||
--- a/test/simple/test-stream2-pipe-error-handling.js
|
||||
+++ b/test/simple/test-stream2-pipe-error-handling.js
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
var common = require('../common');
|
||||
var assert = require('assert');
|
||||
-var stream = require('stream');
|
||||
+var stream = require('../../');
|
||||
|
||||
(function testErrorListenerCatches() {
|
||||
var count = 1000;
|
||||
diff --git a/test/simple/test-stream2-pipe-error-once-listener.js b/test/simple/test-stream2-pipe-error-once-listener.js
|
||||
index 5e8e3cb..53b2616 100755
|
||||
--- a/test/simple/test-stream2-pipe-error-once-listener.js
|
||||
+++ b/test/simple/test-stream2-pipe-error-once-listener.js
|
||||
@@ -24,7 +24,7 @@ var common = require('../common.js');
|
||||
var assert = require('assert');
|
||||
|
||||
var util = require('util');
|
||||
-var stream = require('stream');
|
||||
+var stream = require('../../');
|
||||
|
||||
|
||||
var Read = function() {
|
||||
diff --git a/test/simple/test-stream2-push.js b/test/simple/test-stream2-push.js
|
||||
index b63edc3..eb2b0e9 100644
|
||||
--- a/test/simple/test-stream2-push.js
|
||||
+++ b/test/simple/test-stream2-push.js
|
||||
@@ -20,7 +20,7 @@
|
||||
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
var common = require('../common.js');
|
||||
-var stream = require('stream');
|
||||
+var stream = require('../../');
|
||||
var Readable = stream.Readable;
|
||||
var Writable = stream.Writable;
|
||||
var assert = require('assert');
|
||||
diff --git a/test/simple/test-stream2-read-sync-stack.js b/test/simple/test-stream2-read-sync-stack.js
|
||||
index e8a7305..9740a47 100644
|
||||
--- a/test/simple/test-stream2-read-sync-stack.js
|
||||
+++ b/test/simple/test-stream2-read-sync-stack.js
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
var common = require('../common');
|
||||
var assert = require('assert');
|
||||
-var Readable = require('stream').Readable;
|
||||
+var Readable = require('../../').Readable;
|
||||
var r = new Readable();
|
||||
var N = 256 * 1024;
|
||||
|
||||
diff --git a/test/simple/test-stream2-readable-empty-buffer-no-eof.js b/test/simple/test-stream2-readable-empty-buffer-no-eof.js
|
||||
index cd30178..4b1659d 100644
|
||||
--- a/test/simple/test-stream2-readable-empty-buffer-no-eof.js
|
||||
+++ b/test/simple/test-stream2-readable-empty-buffer-no-eof.js
|
||||
@@ -22,10 +22,9 @@
|
||||
var common = require('../common');
|
||||
var assert = require('assert');
|
||||
|
||||
-var Readable = require('stream').Readable;
|
||||
+var Readable = require('../../').Readable;
|
||||
|
||||
test1();
|
||||
-test2();
|
||||
|
||||
function test1() {
|
||||
var r = new Readable();
|
||||
@@ -88,31 +87,3 @@ function test1() {
|
||||
console.log('ok');
|
||||
});
|
||||
}
|
||||
-
|
||||
-function test2() {
|
||||
- var r = new Readable({ encoding: 'base64' });
|
||||
- var reads = 5;
|
||||
- r._read = function(n) {
|
||||
- if (!reads--)
|
||||
- return r.push(null); // EOF
|
||||
- else
|
||||
- return r.push(new Buffer('x'));
|
||||
- };
|
||||
-
|
||||
- var results = [];
|
||||
- function flow() {
|
||||
- var chunk;
|
||||
- while (null !== (chunk = r.read()))
|
||||
- results.push(chunk + '');
|
||||
- }
|
||||
- r.on('readable', flow);
|
||||
- r.on('end', function() {
|
||||
- results.push('EOF');
|
||||
- });
|
||||
- flow();
|
||||
-
|
||||
- process.on('exit', function() {
|
||||
- assert.deepEqual(results, [ 'eHh4', 'eHg=', 'EOF' ]);
|
||||
- console.log('ok');
|
||||
- });
|
||||
-}
|
||||
diff --git a/test/simple/test-stream2-readable-from-list.js b/test/simple/test-stream2-readable-from-list.js
|
||||
index 7c96ffe..04a96f5 100644
|
||||
--- a/test/simple/test-stream2-readable-from-list.js
|
||||
+++ b/test/simple/test-stream2-readable-from-list.js
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
var assert = require('assert');
|
||||
var common = require('../common.js');
|
||||
-var fromList = require('_stream_readable')._fromList;
|
||||
+var fromList = require('../../lib/_stream_readable')._fromList;
|
||||
|
||||
// tiny node-tap lookalike.
|
||||
var tests = [];
|
||||
diff --git a/test/simple/test-stream2-readable-legacy-drain.js b/test/simple/test-stream2-readable-legacy-drain.js
|
||||
index 675da8e..51fd3d5 100644
|
||||
--- a/test/simple/test-stream2-readable-legacy-drain.js
|
||||
+++ b/test/simple/test-stream2-readable-legacy-drain.js
|
||||
@@ -22,7 +22,7 @@
|
||||
var common = require('../common');
|
||||
var assert = require('assert');
|
||||
|
||||
-var Stream = require('stream');
|
||||
+var Stream = require('../../');
|
||||
var Readable = Stream.Readable;
|
||||
|
||||
var r = new Readable();
|
||||
diff --git a/test/simple/test-stream2-readable-non-empty-end.js b/test/simple/test-stream2-readable-non-empty-end.js
|
||||
index 7314ae7..c971898 100644
|
||||
--- a/test/simple/test-stream2-readable-non-empty-end.js
|
||||
+++ b/test/simple/test-stream2-readable-non-empty-end.js
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
var assert = require('assert');
|
||||
var common = require('../common.js');
|
||||
-var Readable = require('_stream_readable');
|
||||
+var Readable = require('../../lib/_stream_readable');
|
||||
|
||||
var len = 0;
|
||||
var chunks = new Array(10);
|
||||
diff --git a/test/simple/test-stream2-readable-wrap-empty.js b/test/simple/test-stream2-readable-wrap-empty.js
|
||||
index 2e5cf25..fd8a3dc 100644
|
||||
--- a/test/simple/test-stream2-readable-wrap-empty.js
|
||||
+++ b/test/simple/test-stream2-readable-wrap-empty.js
|
||||
@@ -22,7 +22,7 @@
|
||||
var common = require('../common');
|
||||
var assert = require('assert');
|
||||
|
||||
-var Readable = require('_stream_readable');
|
||||
+var Readable = require('../../lib/_stream_readable');
|
||||
var EE = require('events').EventEmitter;
|
||||
|
||||
var oldStream = new EE();
|
||||
diff --git a/test/simple/test-stream2-readable-wrap.js b/test/simple/test-stream2-readable-wrap.js
|
||||
index 90eea01..6b177f7 100644
|
||||
--- a/test/simple/test-stream2-readable-wrap.js
|
||||
+++ b/test/simple/test-stream2-readable-wrap.js
|
||||
@@ -22,8 +22,8 @@
|
||||
var common = require('../common');
|
||||
var assert = require('assert');
|
||||
|
||||
-var Readable = require('_stream_readable');
|
||||
-var Writable = require('_stream_writable');
|
||||
+var Readable = require('../../lib/_stream_readable');
|
||||
+var Writable = require('../../lib/_stream_writable');
|
||||
var EE = require('events').EventEmitter;
|
||||
|
||||
var testRuns = 0, completedRuns = 0;
|
||||
diff --git a/test/simple/test-stream2-set-encoding.js b/test/simple/test-stream2-set-encoding.js
|
||||
index 5d2c32a..685531b 100644
|
||||
--- a/test/simple/test-stream2-set-encoding.js
|
||||
+++ b/test/simple/test-stream2-set-encoding.js
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
var common = require('../common.js');
|
||||
var assert = require('assert');
|
||||
-var R = require('_stream_readable');
|
||||
+var R = require('../../lib/_stream_readable');
|
||||
var util = require('util');
|
||||
|
||||
// tiny node-tap lookalike.
|
||||
diff --git a/test/simple/test-stream2-transform.js b/test/simple/test-stream2-transform.js
|
||||
index 9c9ddd8..a0cacc6 100644
|
||||
--- a/test/simple/test-stream2-transform.js
|
||||
+++ b/test/simple/test-stream2-transform.js
|
||||
@@ -21,8 +21,8 @@
|
||||
|
||||
var assert = require('assert');
|
||||
var common = require('../common.js');
|
||||
-var PassThrough = require('_stream_passthrough');
|
||||
-var Transform = require('_stream_transform');
|
||||
+var PassThrough = require('../../').PassThrough;
|
||||
+var Transform = require('../../').Transform;
|
||||
|
||||
// tiny node-tap lookalike.
|
||||
var tests = [];
|
||||
diff --git a/test/simple/test-stream2-unpipe-drain.js b/test/simple/test-stream2-unpipe-drain.js
|
||||
index d66dc3c..365b327 100644
|
||||
--- a/test/simple/test-stream2-unpipe-drain.js
|
||||
+++ b/test/simple/test-stream2-unpipe-drain.js
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
var common = require('../common.js');
|
||||
var assert = require('assert');
|
||||
-var stream = require('stream');
|
||||
+var stream = require('../../');
|
||||
var crypto = require('crypto');
|
||||
|
||||
var util = require('util');
|
||||
diff --git a/test/simple/test-stream2-unpipe-leak.js b/test/simple/test-stream2-unpipe-leak.js
|
||||
index 99f8746..17c92ae 100644
|
||||
--- a/test/simple/test-stream2-unpipe-leak.js
|
||||
+++ b/test/simple/test-stream2-unpipe-leak.js
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
var common = require('../common.js');
|
||||
var assert = require('assert');
|
||||
-var stream = require('stream');
|
||||
+var stream = require('../../');
|
||||
|
||||
var chunk = new Buffer('hallo');
|
||||
|
||||
diff --git a/test/simple/test-stream2-writable.js b/test/simple/test-stream2-writable.js
|
||||
index 704100c..209c3a6 100644
|
||||
--- a/test/simple/test-stream2-writable.js
|
||||
+++ b/test/simple/test-stream2-writable.js
|
||||
@@ -20,8 +20,8 @@
|
||||
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
var common = require('../common.js');
|
||||
-var W = require('_stream_writable');
|
||||
-var D = require('_stream_duplex');
|
||||
+var W = require('../../').Writable;
|
||||
+var D = require('../../').Duplex;
|
||||
var assert = require('assert');
|
||||
|
||||
var util = require('util');
|
||||
diff --git a/test/simple/test-stream3-pause-then-read.js b/test/simple/test-stream3-pause-then-read.js
|
||||
index b91bde3..2f72c15 100644
|
||||
--- a/test/simple/test-stream3-pause-then-read.js
|
||||
+++ b/test/simple/test-stream3-pause-then-read.js
|
||||
@@ -22,7 +22,7 @@
|
||||
var common = require('../common');
|
||||
var assert = require('assert');
|
||||
|
||||
-var stream = require('stream');
|
||||
+var stream = require('../../');
|
||||
var Readable = stream.Readable;
|
||||
var Writable = stream.Writable;
|
||||
|
89
express-server/node_modules/busboy/node_modules/readable-stream/lib/_stream_duplex.js
generated
vendored
Normal file
89
express-server/node_modules/busboy/node_modules/readable-stream/lib/_stream_duplex.js
generated
vendored
Normal file
@ -0,0 +1,89 @@
|
||||
// Copyright Joyent, Inc. and other Node contributors.
|
||||
//
|
||||
// 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.
|
||||
|
||||
// a duplex stream is just a stream that is both readable and writable.
|
||||
// Since JS doesn't have multiple prototypal inheritance, this class
|
||||
// prototypally inherits from Readable, and then parasitically from
|
||||
// Writable.
|
||||
|
||||
module.exports = Duplex;
|
||||
|
||||
/*<replacement>*/
|
||||
var objectKeys = Object.keys || function (obj) {
|
||||
var keys = [];
|
||||
for (var key in obj) keys.push(key);
|
||||
return keys;
|
||||
}
|
||||
/*</replacement>*/
|
||||
|
||||
|
||||
/*<replacement>*/
|
||||
var util = require('core-util-is');
|
||||
util.inherits = require('inherits');
|
||||
/*</replacement>*/
|
||||
|
||||
var Readable = require('./_stream_readable');
|
||||
var Writable = require('./_stream_writable');
|
||||
|
||||
util.inherits(Duplex, Readable);
|
||||
|
||||
forEach(objectKeys(Writable.prototype), function(method) {
|
||||
if (!Duplex.prototype[method])
|
||||
Duplex.prototype[method] = Writable.prototype[method];
|
||||
});
|
||||
|
||||
function Duplex(options) {
|
||||
if (!(this instanceof Duplex))
|
||||
return new Duplex(options);
|
||||
|
||||
Readable.call(this, options);
|
||||
Writable.call(this, options);
|
||||
|
||||
if (options && options.readable === false)
|
||||
this.readable = false;
|
||||
|
||||
if (options && options.writable === false)
|
||||
this.writable = false;
|
||||
|
||||
this.allowHalfOpen = true;
|
||||
if (options && options.allowHalfOpen === false)
|
||||
this.allowHalfOpen = false;
|
||||
|
||||
this.once('end', onend);
|
||||
}
|
||||
|
||||
// the no-half-open enforcer
|
||||
function onend() {
|
||||
// if we allow half-open state, or if the writable side ended,
|
||||
// then we're ok.
|
||||
if (this.allowHalfOpen || this._writableState.ended)
|
||||
return;
|
||||
|
||||
// no more data can be written.
|
||||
// But allow more writes to happen in this tick.
|
||||
process.nextTick(this.end.bind(this));
|
||||
}
|
||||
|
||||
function forEach (xs, f) {
|
||||
for (var i = 0, l = xs.length; i < l; i++) {
|
||||
f(xs[i], i);
|
||||
}
|
||||
}
|
46
express-server/node_modules/busboy/node_modules/readable-stream/lib/_stream_passthrough.js
generated
vendored
Normal file
46
express-server/node_modules/busboy/node_modules/readable-stream/lib/_stream_passthrough.js
generated
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
// Copyright Joyent, Inc. and other Node contributors.
|
||||
//
|
||||
// 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.
|
||||
|
||||
// a passthrough stream.
|
||||
// basically just the most minimal sort of Transform stream.
|
||||
// Every written chunk gets output as-is.
|
||||
|
||||
module.exports = PassThrough;
|
||||
|
||||
var Transform = require('./_stream_transform');
|
||||
|
||||
/*<replacement>*/
|
||||
var util = require('core-util-is');
|
||||
util.inherits = require('inherits');
|
||||
/*</replacement>*/
|
||||
|
||||
util.inherits(PassThrough, Transform);
|
||||
|
||||
function PassThrough(options) {
|
||||
if (!(this instanceof PassThrough))
|
||||
return new PassThrough(options);
|
||||
|
||||
Transform.call(this, options);
|
||||
}
|
||||
|
||||
PassThrough.prototype._transform = function(chunk, encoding, cb) {
|
||||
cb(null, chunk);
|
||||
};
|
951
express-server/node_modules/busboy/node_modules/readable-stream/lib/_stream_readable.js
generated
vendored
Normal file
951
express-server/node_modules/busboy/node_modules/readable-stream/lib/_stream_readable.js
generated
vendored
Normal file
@ -0,0 +1,951 @@
|
||||
// Copyright Joyent, Inc. and other Node contributors.
|
||||
//
|
||||
// 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.
|
||||
|
||||
module.exports = Readable;
|
||||
|
||||
/*<replacement>*/
|
||||
var isArray = require('isarray');
|
||||
/*</replacement>*/
|
||||
|
||||
|
||||
/*<replacement>*/
|
||||
var Buffer = require('buffer').Buffer;
|
||||
/*</replacement>*/
|
||||
|
||||
Readable.ReadableState = ReadableState;
|
||||
|
||||
var EE = require('events').EventEmitter;
|
||||
|
||||
/*<replacement>*/
|
||||
if (!EE.listenerCount) EE.listenerCount = function(emitter, type) {
|
||||
return emitter.listeners(type).length;
|
||||
};
|
||||
/*</replacement>*/
|
||||
|
||||
var Stream = require('stream');
|
||||
|
||||
/*<replacement>*/
|
||||
var util = require('core-util-is');
|
||||
util.inherits = require('inherits');
|
||||
/*</replacement>*/
|
||||
|
||||
var StringDecoder;
|
||||
|
||||
|
||||
/*<replacement>*/
|
||||
var debug = require('util');
|
||||
if (debug && debug.debuglog) {
|
||||
debug = debug.debuglog('stream');
|
||||
} else {
|
||||
debug = function () {};
|
||||
}
|
||||
/*</replacement>*/
|
||||
|
||||
|
||||
util.inherits(Readable, Stream);
|
||||
|
||||
function ReadableState(options, stream) {
|
||||
var Duplex = require('./_stream_duplex');
|
||||
|
||||
options = options || {};
|
||||
|
||||
// the point at which it stops calling _read() to fill the buffer
|
||||
// Note: 0 is a valid value, means "don't call _read preemptively ever"
|
||||
var hwm = options.highWaterMark;
|
||||
var defaultHwm = options.objectMode ? 16 : 16 * 1024;
|
||||
this.highWaterMark = (hwm || hwm === 0) ? hwm : defaultHwm;
|
||||
|
||||
// cast to ints.
|
||||
this.highWaterMark = ~~this.highWaterMark;
|
||||
|
||||
this.buffer = [];
|
||||
this.length = 0;
|
||||
this.pipes = null;
|
||||
this.pipesCount = 0;
|
||||
this.flowing = null;
|
||||
this.ended = false;
|
||||
this.endEmitted = false;
|
||||
this.reading = false;
|
||||
|
||||
// a flag to be able to tell if the onwrite cb is called immediately,
|
||||
// or on a later tick. We set this to true at first, because any
|
||||
// actions that shouldn't happen until "later" should generally also
|
||||
// not happen before the first write call.
|
||||
this.sync = true;
|
||||
|
||||
// whenever we return null, then we set a flag to say
|
||||
// that we're awaiting a 'readable' event emission.
|
||||
this.needReadable = false;
|
||||
this.emittedReadable = false;
|
||||
this.readableListening = false;
|
||||
|
||||
|
||||
// object stream flag. Used to make read(n) ignore n and to
|
||||
// make all the buffer merging and length checks go away
|
||||
this.objectMode = !!options.objectMode;
|
||||
|
||||
if (stream instanceof Duplex)
|
||||
this.objectMode = this.objectMode || !!options.readableObjectMode;
|
||||
|
||||
// Crypto is kind of old and crusty. Historically, its default string
|
||||
// encoding is 'binary' so we have to make this configurable.
|
||||
// Everything else in the universe uses 'utf8', though.
|
||||
this.defaultEncoding = options.defaultEncoding || 'utf8';
|
||||
|
||||
// when piping, we only care about 'readable' events that happen
|
||||
// after read()ing all the bytes and not getting any pushback.
|
||||
this.ranOut = false;
|
||||
|
||||
// the number of writers that are awaiting a drain event in .pipe()s
|
||||
this.awaitDrain = 0;
|
||||
|
||||
// if true, a maybeReadMore has been scheduled
|
||||
this.readingMore = false;
|
||||
|
||||
this.decoder = null;
|
||||
this.encoding = null;
|
||||
if (options.encoding) {
|
||||
if (!StringDecoder)
|
||||
StringDecoder = require('string_decoder/').StringDecoder;
|
||||
this.decoder = new StringDecoder(options.encoding);
|
||||
this.encoding = options.encoding;
|
||||
}
|
||||
}
|
||||
|
||||
function Readable(options) {
|
||||
var Duplex = require('./_stream_duplex');
|
||||
|
||||
if (!(this instanceof Readable))
|
||||
return new Readable(options);
|
||||
|
||||
this._readableState = new ReadableState(options, this);
|
||||
|
||||
// legacy
|
||||
this.readable = true;
|
||||
|
||||
Stream.call(this);
|
||||
}
|
||||
|
||||
// Manually shove something into the read() buffer.
|
||||
// This returns true if the highWaterMark has not been hit yet,
|
||||
// similar to how Writable.write() returns true if you should
|
||||
// write() some more.
|
||||
Readable.prototype.push = function(chunk, encoding) {
|
||||
var state = this._readableState;
|
||||
|
||||
if (util.isString(chunk) && !state.objectMode) {
|
||||
encoding = encoding || state.defaultEncoding;
|
||||
if (encoding !== state.encoding) {
|
||||
chunk = new Buffer(chunk, encoding);
|
||||
encoding = '';
|
||||
}
|
||||
}
|
||||
|
||||
return readableAddChunk(this, state, chunk, encoding, false);
|
||||
};
|
||||
|
||||
// Unshift should *always* be something directly out of read()
|
||||
Readable.prototype.unshift = function(chunk) {
|
||||
var state = this._readableState;
|
||||
return readableAddChunk(this, state, chunk, '', true);
|
||||
};
|
||||
|
||||
function readableAddChunk(stream, state, chunk, encoding, addToFront) {
|
||||
var er = chunkInvalid(state, chunk);
|
||||
if (er) {
|
||||
stream.emit('error', er);
|
||||
} else if (util.isNullOrUndefined(chunk)) {
|
||||
state.reading = false;
|
||||
if (!state.ended)
|
||||
onEofChunk(stream, state);
|
||||
} else if (state.objectMode || chunk && chunk.length > 0) {
|
||||
if (state.ended && !addToFront) {
|
||||
var e = new Error('stream.push() after EOF');
|
||||
stream.emit('error', e);
|
||||
} else if (state.endEmitted && addToFront) {
|
||||
var e = new Error('stream.unshift() after end event');
|
||||
stream.emit('error', e);
|
||||
} else {
|
||||
if (state.decoder && !addToFront && !encoding)
|
||||
chunk = state.decoder.write(chunk);
|
||||
|
||||
if (!addToFront)
|
||||
state.reading = false;
|
||||
|
||||
// if we want the data now, just emit it.
|
||||
if (state.flowing && state.length === 0 && !state.sync) {
|
||||
stream.emit('data', chunk);
|
||||
stream.read(0);
|
||||
} else {
|
||||
// update the buffer info.
|
||||
state.length += state.objectMode ? 1 : chunk.length;
|
||||
if (addToFront)
|
||||
state.buffer.unshift(chunk);
|
||||
else
|
||||
state.buffer.push(chunk);
|
||||
|
||||
if (state.needReadable)
|
||||
emitReadable(stream);
|
||||
}
|
||||
|
||||
maybeReadMore(stream, state);
|
||||
}
|
||||
} else if (!addToFront) {
|
||||
state.reading = false;
|
||||
}
|
||||
|
||||
return needMoreData(state);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// if it's past the high water mark, we can push in some more.
|
||||
// Also, if we have no data yet, we can stand some
|
||||
// more bytes. This is to work around cases where hwm=0,
|
||||
// such as the repl. Also, if the push() triggered a
|
||||
// readable event, and the user called read(largeNumber) such that
|
||||
// needReadable was set, then we ought to push more, so that another
|
||||
// 'readable' event will be triggered.
|
||||
function needMoreData(state) {
|
||||
return !state.ended &&
|
||||
(state.needReadable ||
|
||||
state.length < state.highWaterMark ||
|
||||
state.length === 0);
|
||||
}
|
||||
|
||||
// backwards compatibility.
|
||||
Readable.prototype.setEncoding = function(enc) {
|
||||
if (!StringDecoder)
|
||||
StringDecoder = require('string_decoder/').StringDecoder;
|
||||
this._readableState.decoder = new StringDecoder(enc);
|
||||
this._readableState.encoding = enc;
|
||||
return this;
|
||||
};
|
||||
|
||||
// Don't raise the hwm > 128MB
|
||||
var MAX_HWM = 0x800000;
|
||||
function roundUpToNextPowerOf2(n) {
|
||||
if (n >= MAX_HWM) {
|
||||
n = MAX_HWM;
|
||||
} else {
|
||||
// Get the next highest power of 2
|
||||
n--;
|
||||
for (var p = 1; p < 32; p <<= 1) n |= n >> p;
|
||||
n++;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
function howMuchToRead(n, state) {
|
||||
if (state.length === 0 && state.ended)
|
||||
return 0;
|
||||
|
||||
if (state.objectMode)
|
||||
return n === 0 ? 0 : 1;
|
||||
|
||||
if (isNaN(n) || util.isNull(n)) {
|
||||
// only flow one buffer at a time
|
||||
if (state.flowing && state.buffer.length)
|
||||
return state.buffer[0].length;
|
||||
else
|
||||
return state.length;
|
||||
}
|
||||
|
||||
if (n <= 0)
|
||||
return 0;
|
||||
|
||||
// If we're asking for more than the target buffer level,
|
||||
// then raise the water mark. Bump up to the next highest
|
||||
// power of 2, to prevent increasing it excessively in tiny
|
||||
// amounts.
|
||||
if (n > state.highWaterMark)
|
||||
state.highWaterMark = roundUpToNextPowerOf2(n);
|
||||
|
||||
// don't have that much. return null, unless we've ended.
|
||||
if (n > state.length) {
|
||||
if (!state.ended) {
|
||||
state.needReadable = true;
|
||||
return 0;
|
||||
} else
|
||||
return state.length;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
// you can override either this method, or the async _read(n) below.
|
||||
Readable.prototype.read = function(n) {
|
||||
debug('read', n);
|
||||
var state = this._readableState;
|
||||
var nOrig = n;
|
||||
|
||||
if (!util.isNumber(n) || n > 0)
|
||||
state.emittedReadable = false;
|
||||
|
||||
// if we're doing read(0) to trigger a readable event, but we
|
||||
// already have a bunch of data in the buffer, then just trigger
|
||||
// the 'readable' event and move on.
|
||||
if (n === 0 &&
|
||||
state.needReadable &&
|
||||
(state.length >= state.highWaterMark || state.ended)) {
|
||||
debug('read: emitReadable', state.length, state.ended);
|
||||
if (state.length === 0 && state.ended)
|
||||
endReadable(this);
|
||||
else
|
||||
emitReadable(this);
|
||||
return null;
|
||||
}
|
||||
|
||||
n = howMuchToRead(n, state);
|
||||
|
||||
// if we've ended, and we're now clear, then finish it up.
|
||||
if (n === 0 && state.ended) {
|
||||
if (state.length === 0)
|
||||
endReadable(this);
|
||||
return null;
|
||||
}
|
||||
|
||||
// All the actual chunk generation logic needs to be
|
||||
// *below* the call to _read. The reason is that in certain
|
||||
// synthetic stream cases, such as passthrough streams, _read
|
||||
// may be a completely synchronous operation which may change
|
||||
// the state of the read buffer, providing enough data when
|
||||
// before there was *not* enough.
|
||||
//
|
||||
// So, the steps are:
|
||||
// 1. Figure out what the state of things will be after we do
|
||||
// a read from the buffer.
|
||||
//
|
||||
// 2. If that resulting state will trigger a _read, then call _read.
|
||||
// Note that this may be asynchronous, or synchronous. Yes, it is
|
||||
// deeply ugly to write APIs this way, but that still doesn't mean
|
||||
// that the Readable class should behave improperly, as streams are
|
||||
// designed to be sync/async agnostic.
|
||||
// Take note if the _read call is sync or async (ie, if the read call
|
||||
// has returned yet), so that we know whether or not it's safe to emit
|
||||
// 'readable' etc.
|
||||
//
|
||||
// 3. Actually pull the requested chunks out of the buffer and return.
|
||||
|
||||
// if we need a readable event, then we need to do some reading.
|
||||
var doRead = state.needReadable;
|
||||
debug('need readable', doRead);
|
||||
|
||||
// if we currently have less than the highWaterMark, then also read some
|
||||
if (state.length === 0 || state.length - n < state.highWaterMark) {
|
||||
doRead = true;
|
||||
debug('length less than watermark', doRead);
|
||||
}
|
||||
|
||||
// however, if we've ended, then there's no point, and if we're already
|
||||
// reading, then it's unnecessary.
|
||||
if (state.ended || state.reading) {
|
||||
doRead = false;
|
||||
debug('reading or ended', doRead);
|
||||
}
|
||||
|
||||
if (doRead) {
|
||||
debug('do read');
|
||||
state.reading = true;
|
||||
state.sync = true;
|
||||
// if the length is currently zero, then we *need* a readable event.
|
||||
if (state.length === 0)
|
||||
state.needReadable = true;
|
||||
// call internal read method
|
||||
this._read(state.highWaterMark);
|
||||
state.sync = false;
|
||||
}
|
||||
|
||||
// If _read pushed data synchronously, then `reading` will be false,
|
||||
// and we need to re-evaluate how much data we can return to the user.
|
||||
if (doRead && !state.reading)
|
||||
n = howMuchToRead(nOrig, state);
|
||||
|
||||
var ret;
|
||||
if (n > 0)
|
||||
ret = fromList(n, state);
|
||||
else
|
||||
ret = null;
|
||||
|
||||
if (util.isNull(ret)) {
|
||||
state.needReadable = true;
|
||||
n = 0;
|
||||
}
|
||||
|
||||
state.length -= n;
|
||||
|
||||
// If we have nothing in the buffer, then we want to know
|
||||
// as soon as we *do* get something into the buffer.
|
||||
if (state.length === 0 && !state.ended)
|
||||
state.needReadable = true;
|
||||
|
||||
// If we tried to read() past the EOF, then emit end on the next tick.
|
||||
if (nOrig !== n && state.ended && state.length === 0)
|
||||
endReadable(this);
|
||||
|
||||
if (!util.isNull(ret))
|
||||
this.emit('data', ret);
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
function chunkInvalid(state, chunk) {
|
||||
var er = null;
|
||||
if (!util.isBuffer(chunk) &&
|
||||
!util.isString(chunk) &&
|
||||
!util.isNullOrUndefined(chunk) &&
|
||||
!state.objectMode) {
|
||||
er = new TypeError('Invalid non-string/buffer chunk');
|
||||
}
|
||||
return er;
|
||||
}
|
||||
|
||||
|
||||
function onEofChunk(stream, state) {
|
||||
if (state.decoder && !state.ended) {
|
||||
var chunk = state.decoder.end();
|
||||
if (chunk && chunk.length) {
|
||||
state.buffer.push(chunk);
|
||||
state.length += state.objectMode ? 1 : chunk.length;
|
||||
}
|
||||
}
|
||||
state.ended = true;
|
||||
|
||||
// emit 'readable' now to make sure it gets picked up.
|
||||
emitReadable(stream);
|
||||
}
|
||||
|
||||
// Don't emit readable right away in sync mode, because this can trigger
|
||||
// another read() call => stack overflow. This way, it might trigger
|
||||
// a nextTick recursion warning, but that's not so bad.
|
||||
function emitReadable(stream) {
|
||||
var state = stream._readableState;
|
||||
state.needReadable = false;
|
||||
if (!state.emittedReadable) {
|
||||
debug('emitReadable', state.flowing);
|
||||
state.emittedReadable = true;
|
||||
if (state.sync)
|
||||
process.nextTick(function() {
|
||||
emitReadable_(stream);
|
||||
});
|
||||
else
|
||||
emitReadable_(stream);
|
||||
}
|
||||
}
|
||||
|
||||
function emitReadable_(stream) {
|
||||
debug('emit readable');
|
||||
stream.emit('readable');
|
||||
flow(stream);
|
||||
}
|
||||
|
||||
|
||||
// at this point, the user has presumably seen the 'readable' event,
|
||||
// and called read() to consume some data. that may have triggered
|
||||
// in turn another _read(n) call, in which case reading = true if
|
||||
// it's in progress.
|
||||
// However, if we're not ended, or reading, and the length < hwm,
|
||||
// then go ahead and try to read some more preemptively.
|
||||
function maybeReadMore(stream, state) {
|
||||
if (!state.readingMore) {
|
||||
state.readingMore = true;
|
||||
process.nextTick(function() {
|
||||
maybeReadMore_(stream, state);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function maybeReadMore_(stream, state) {
|
||||
var len = state.length;
|
||||
while (!state.reading && !state.flowing && !state.ended &&
|
||||
state.length < state.highWaterMark) {
|
||||
debug('maybeReadMore read 0');
|
||||
stream.read(0);
|
||||
if (len === state.length)
|
||||
// didn't get any data, stop spinning.
|
||||
break;
|
||||
else
|
||||
len = state.length;
|
||||
}
|
||||
state.readingMore = false;
|
||||
}
|
||||
|
||||
// abstract method. to be overridden in specific implementation classes.
|
||||
// call cb(er, data) where data is <= n in length.
|
||||
// for virtual (non-string, non-buffer) streams, "length" is somewhat
|
||||
// arbitrary, and perhaps not very meaningful.
|
||||
Readable.prototype._read = function(n) {
|
||||
this.emit('error', new Error('not implemented'));
|
||||
};
|
||||
|
||||
Readable.prototype.pipe = function(dest, pipeOpts) {
|
||||
var src = this;
|
||||
var state = this._readableState;
|
||||
|
||||
switch (state.pipesCount) {
|
||||
case 0:
|
||||
state.pipes = dest;
|
||||
break;
|
||||
case 1:
|
||||
state.pipes = [state.pipes, dest];
|
||||
break;
|
||||
default:
|
||||
state.pipes.push(dest);
|
||||
break;
|
||||
}
|
||||
state.pipesCount += 1;
|
||||
debug('pipe count=%d opts=%j', state.pipesCount, pipeOpts);
|
||||
|
||||
var doEnd = (!pipeOpts || pipeOpts.end !== false) &&
|
||||
dest !== process.stdout &&
|
||||
dest !== process.stderr;
|
||||
|
||||
var endFn = doEnd ? onend : cleanup;
|
||||
if (state.endEmitted)
|
||||
process.nextTick(endFn);
|
||||
else
|
||||
src.once('end', endFn);
|
||||
|
||||
dest.on('unpipe', onunpipe);
|
||||
function onunpipe(readable) {
|
||||
debug('onunpipe');
|
||||
if (readable === src) {
|
||||
cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
function onend() {
|
||||
debug('onend');
|
||||
dest.end();
|
||||
}
|
||||
|
||||
// when the dest drains, it reduces the awaitDrain counter
|
||||
// on the source. This would be more elegant with a .once()
|
||||
// handler in flow(), but adding and removing repeatedly is
|
||||
// too slow.
|
||||
var ondrain = pipeOnDrain(src);
|
||||
dest.on('drain', ondrain);
|
||||
|
||||
function cleanup() {
|
||||
debug('cleanup');
|
||||
// cleanup event handlers once the pipe is broken
|
||||
dest.removeListener('close', onclose);
|
||||
dest.removeListener('finish', onfinish);
|
||||
dest.removeListener('drain', ondrain);
|
||||
dest.removeListener('error', onerror);
|
||||
dest.removeListener('unpipe', onunpipe);
|
||||
src.removeListener('end', onend);
|
||||
src.removeListener('end', cleanup);
|
||||
src.removeListener('data', ondata);
|
||||
|
||||
// if the reader is waiting for a drain event from this
|
||||
// specific writer, then it would cause it to never start
|
||||
// flowing again.
|
||||
// So, if this is awaiting a drain, then we just call it now.
|
||||
// If we don't know, then assume that we are waiting for one.
|
||||
if (state.awaitDrain &&
|
||||
(!dest._writableState || dest._writableState.needDrain))
|
||||
ondrain();
|
||||
}
|
||||
|
||||
src.on('data', ondata);
|
||||
function ondata(chunk) {
|
||||
debug('ondata');
|
||||
var ret = dest.write(chunk);
|
||||
if (false === ret) {
|
||||
debug('false write response, pause',
|
||||
src._readableState.awaitDrain);
|
||||
src._readableState.awaitDrain++;
|
||||
src.pause();
|
||||
}
|
||||
}
|
||||
|
||||
// if the dest has an error, then stop piping into it.
|
||||
// however, don't suppress the throwing behavior for this.
|
||||
function onerror(er) {
|
||||
debug('onerror', er);
|
||||
unpipe();
|
||||
dest.removeListener('error', onerror);
|
||||
if (EE.listenerCount(dest, 'error') === 0)
|
||||
dest.emit('error', er);
|
||||
}
|
||||
// This is a brutally ugly hack to make sure that our error handler
|
||||
// is attached before any userland ones. NEVER DO THIS.
|
||||
if (!dest._events || !dest._events.error)
|
||||
dest.on('error', onerror);
|
||||
else if (isArray(dest._events.error))
|
||||
dest._events.error.unshift(onerror);
|
||||
else
|
||||
dest._events.error = [onerror, dest._events.error];
|
||||
|
||||
|
||||
|
||||
// Both close and finish should trigger unpipe, but only once.
|
||||
function onclose() {
|
||||
dest.removeListener('finish', onfinish);
|
||||
unpipe();
|
||||
}
|
||||
dest.once('close', onclose);
|
||||
function onfinish() {
|
||||
debug('onfinish');
|
||||
dest.removeListener('close', onclose);
|
||||
unpipe();
|
||||
}
|
||||
dest.once('finish', onfinish);
|
||||
|
||||
function unpipe() {
|
||||
debug('unpipe');
|
||||
src.unpipe(dest);
|
||||
}
|
||||
|
||||
// tell the dest that it's being piped to
|
||||
dest.emit('pipe', src);
|
||||
|
||||
// start the flow if it hasn't been started already.
|
||||
if (!state.flowing) {
|
||||
debug('pipe resume');
|
||||
src.resume();
|
||||
}
|
||||
|
||||
return dest;
|
||||
};
|
||||
|
||||
function pipeOnDrain(src) {
|
||||
return function() {
|
||||
var state = src._readableState;
|
||||
debug('pipeOnDrain', state.awaitDrain);
|
||||
if (state.awaitDrain)
|
||||
state.awaitDrain--;
|
||||
if (state.awaitDrain === 0 && EE.listenerCount(src, 'data')) {
|
||||
state.flowing = true;
|
||||
flow(src);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Readable.prototype.unpipe = function(dest) {
|
||||
var state = this._readableState;
|
||||
|
||||
// if we're not piping anywhere, then do nothing.
|
||||
if (state.pipesCount === 0)
|
||||
return this;
|
||||
|
||||
// just one destination. most common case.
|
||||
if (state.pipesCount === 1) {
|
||||
// passed in one, but it's not the right one.
|
||||
if (dest && dest !== state.pipes)
|
||||
return this;
|
||||
|
||||
if (!dest)
|
||||
dest = state.pipes;
|
||||
|
||||
// got a match.
|
||||
state.pipes = null;
|
||||
state.pipesCount = 0;
|
||||
state.flowing = false;
|
||||
if (dest)
|
||||
dest.emit('unpipe', this);
|
||||
return this;
|
||||
}
|
||||
|
||||
// slow case. multiple pipe destinations.
|
||||
|
||||
if (!dest) {
|
||||
// remove all.
|
||||
var dests = state.pipes;
|
||||
var len = state.pipesCount;
|
||||
state.pipes = null;
|
||||
state.pipesCount = 0;
|
||||
state.flowing = false;
|
||||
|
||||
for (var i = 0; i < len; i++)
|
||||
dests[i].emit('unpipe', this);
|
||||
return this;
|
||||
}
|
||||
|
||||
// try to find the right one.
|
||||
var i = indexOf(state.pipes, dest);
|
||||
if (i === -1)
|
||||
return this;
|
||||
|
||||
state.pipes.splice(i, 1);
|
||||
state.pipesCount -= 1;
|
||||
if (state.pipesCount === 1)
|
||||
state.pipes = state.pipes[0];
|
||||
|
||||
dest.emit('unpipe', this);
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
// set up data events if they are asked for
|
||||
// Ensure readable listeners eventually get something
|
||||
Readable.prototype.on = function(ev, fn) {
|
||||
var res = Stream.prototype.on.call(this, ev, fn);
|
||||
|
||||
// If listening to data, and it has not explicitly been paused,
|
||||
// then call resume to start the flow of data on the next tick.
|
||||
if (ev === 'data' && false !== this._readableState.flowing) {
|
||||
this.resume();
|
||||
}
|
||||
|
||||
if (ev === 'readable' && this.readable) {
|
||||
var state = this._readableState;
|
||||
if (!state.readableListening) {
|
||||
state.readableListening = true;
|
||||
state.emittedReadable = false;
|
||||
state.needReadable = true;
|
||||
if (!state.reading) {
|
||||
var self = this;
|
||||
process.nextTick(function() {
|
||||
debug('readable nexttick read 0');
|
||||
self.read(0);
|
||||
});
|
||||
} else if (state.length) {
|
||||
emitReadable(this, state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
};
|
||||
Readable.prototype.addListener = Readable.prototype.on;
|
||||
|
||||
// pause() and resume() are remnants of the legacy readable stream API
|
||||
// If the user uses them, then switch into old mode.
|
||||
Readable.prototype.resume = function() {
|
||||
var state = this._readableState;
|
||||
if (!state.flowing) {
|
||||
debug('resume');
|
||||
state.flowing = true;
|
||||
if (!state.reading) {
|
||||
debug('resume read 0');
|
||||
this.read(0);
|
||||
}
|
||||
resume(this, state);
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
function resume(stream, state) {
|
||||
if (!state.resumeScheduled) {
|
||||
state.resumeScheduled = true;
|
||||
process.nextTick(function() {
|
||||
resume_(stream, state);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function resume_(stream, state) {
|
||||
state.resumeScheduled = false;
|
||||
stream.emit('resume');
|
||||
flow(stream);
|
||||
if (state.flowing && !state.reading)
|
||||
stream.read(0);
|
||||
}
|
||||
|
||||
Readable.prototype.pause = function() {
|
||||
debug('call pause flowing=%j', this._readableState.flowing);
|
||||
if (false !== this._readableState.flowing) {
|
||||
debug('pause');
|
||||
this._readableState.flowing = false;
|
||||
this.emit('pause');
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
function flow(stream) {
|
||||
var state = stream._readableState;
|
||||
debug('flow', state.flowing);
|
||||
if (state.flowing) {
|
||||
do {
|
||||
var chunk = stream.read();
|
||||
} while (null !== chunk && state.flowing);
|
||||
}
|
||||
}
|
||||
|
||||
// wrap an old-style stream as the async data source.
|
||||
// This is *not* part of the readable stream interface.
|
||||
// It is an ugly unfortunate mess of history.
|
||||
Readable.prototype.wrap = function(stream) {
|
||||
var state = this._readableState;
|
||||
var paused = false;
|
||||
|
||||
var self = this;
|
||||
stream.on('end', function() {
|
||||
debug('wrapped end');
|
||||
if (state.decoder && !state.ended) {
|
||||
var chunk = state.decoder.end();
|
||||
if (chunk && chunk.length)
|
||||
self.push(chunk);
|
||||
}
|
||||
|
||||
self.push(null);
|
||||
});
|
||||
|
||||
stream.on('data', function(chunk) {
|
||||
debug('wrapped data');
|
||||
if (state.decoder)
|
||||
chunk = state.decoder.write(chunk);
|
||||
if (!chunk || !state.objectMode && !chunk.length)
|
||||
return;
|
||||
|
||||
var ret = self.push(chunk);
|
||||
if (!ret) {
|
||||
paused = true;
|
||||
stream.pause();
|
||||
}
|
||||
});
|
||||
|
||||
// proxy all the other methods.
|
||||
// important when wrapping filters and duplexes.
|
||||
for (var i in stream) {
|
||||
if (util.isFunction(stream[i]) && util.isUndefined(this[i])) {
|
||||
this[i] = function(method) { return function() {
|
||||
return stream[method].apply(stream, arguments);
|
||||
}}(i);
|
||||
}
|
||||
}
|
||||
|
||||
// proxy certain important events.
|
||||
var events = ['error', 'close', 'destroy', 'pause', 'resume'];
|
||||
forEach(events, function(ev) {
|
||||
stream.on(ev, self.emit.bind(self, ev));
|
||||
});
|
||||
|
||||
// when we try to consume some more bytes, simply unpause the
|
||||
// underlying stream.
|
||||
self._read = function(n) {
|
||||
debug('wrapped _read', n);
|
||||
if (paused) {
|
||||
paused = false;
|
||||
stream.resume();
|
||||
}
|
||||
};
|
||||
|
||||
return self;
|
||||
};
|
||||
|
||||
|
||||
|
||||
// exposed for testing purposes only.
|
||||
Readable._fromList = fromList;
|
||||
|
||||
// Pluck off n bytes from an array of buffers.
|
||||
// Length is the combined lengths of all the buffers in the list.
|
||||
function fromList(n, state) {
|
||||
var list = state.buffer;
|
||||
var length = state.length;
|
||||
var stringMode = !!state.decoder;
|
||||
var objectMode = !!state.objectMode;
|
||||
var ret;
|
||||
|
||||
// nothing in the list, definitely empty.
|
||||
if (list.length === 0)
|
||||
return null;
|
||||
|
||||
if (length === 0)
|
||||
ret = null;
|
||||
else if (objectMode)
|
||||
ret = list.shift();
|
||||
else if (!n || n >= length) {
|
||||
// read it all, truncate the array.
|
||||
if (stringMode)
|
||||
ret = list.join('');
|
||||
else
|
||||
ret = Buffer.concat(list, length);
|
||||
list.length = 0;
|
||||
} else {
|
||||
// read just some of it.
|
||||
if (n < list[0].length) {
|
||||
// just take a part of the first list item.
|
||||
// slice is the same for buffers and strings.
|
||||
var buf = list[0];
|
||||
ret = buf.slice(0, n);
|
||||
list[0] = buf.slice(n);
|
||||
} else if (n === list[0].length) {
|
||||
// first list is a perfect match
|
||||
ret = list.shift();
|
||||
} else {
|
||||
// complex case.
|
||||
// we have enough to cover it, but it spans past the first buffer.
|
||||
if (stringMode)
|
||||
ret = '';
|
||||
else
|
||||
ret = new Buffer(n);
|
||||
|
||||
var c = 0;
|
||||
for (var i = 0, l = list.length; i < l && c < n; i++) {
|
||||
var buf = list[0];
|
||||
var cpy = Math.min(n - c, buf.length);
|
||||
|
||||
if (stringMode)
|
||||
ret += buf.slice(0, cpy);
|
||||
else
|
||||
buf.copy(ret, c, 0, cpy);
|
||||
|
||||
if (cpy < buf.length)
|
||||
list[0] = buf.slice(cpy);
|
||||
else
|
||||
list.shift();
|
||||
|
||||
c += cpy;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
function endReadable(stream) {
|
||||
var state = stream._readableState;
|
||||
|
||||
// If we get here before consuming all the bytes, then that is a
|
||||
// bug in node. Should never happen.
|
||||
if (state.length > 0)
|
||||
throw new Error('endReadable called on non-empty stream');
|
||||
|
||||
if (!state.endEmitted) {
|
||||
state.ended = true;
|
||||
process.nextTick(function() {
|
||||
// Check that we didn't get one last unshift.
|
||||
if (!state.endEmitted && state.length === 0) {
|
||||
state.endEmitted = true;
|
||||
stream.readable = false;
|
||||
stream.emit('end');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function forEach (xs, f) {
|
||||
for (var i = 0, l = xs.length; i < l; i++) {
|
||||
f(xs[i], i);
|
||||
}
|
||||
}
|
||||
|
||||
function indexOf (xs, x) {
|
||||
for (var i = 0, l = xs.length; i < l; i++) {
|
||||
if (xs[i] === x) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
209
express-server/node_modules/busboy/node_modules/readable-stream/lib/_stream_transform.js
generated
vendored
Normal file
209
express-server/node_modules/busboy/node_modules/readable-stream/lib/_stream_transform.js
generated
vendored
Normal file
@ -0,0 +1,209 @@
|
||||
// Copyright Joyent, Inc. and other Node contributors.
|
||||
//
|
||||
// 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.
|
||||
|
||||
|
||||
// a transform stream is a readable/writable stream where you do
|
||||
// something with the data. Sometimes it's called a "filter",
|
||||
// but that's not a great name for it, since that implies a thing where
|
||||
// some bits pass through, and others are simply ignored. (That would
|
||||
// be a valid example of a transform, of course.)
|
||||
//
|
||||
// While the output is causally related to the input, it's not a
|
||||
// necessarily symmetric or synchronous transformation. For example,
|
||||
// a zlib stream might take multiple plain-text writes(), and then
|
||||
// emit a single compressed chunk some time in the future.
|
||||
//
|
||||
// Here's how this works:
|
||||
//
|
||||
// The Transform stream has all the aspects of the readable and writable
|
||||
// stream classes. When you write(chunk), that calls _write(chunk,cb)
|
||||
// internally, and returns false if there's a lot of pending writes
|
||||
// buffered up. When you call read(), that calls _read(n) until
|
||||
// there's enough pending readable data buffered up.
|
||||
//
|
||||
// In a transform stream, the written data is placed in a buffer. When
|
||||
// _read(n) is called, it transforms the queued up data, calling the
|
||||
// buffered _write cb's as it consumes chunks. If consuming a single
|
||||
// written chunk would result in multiple output chunks, then the first
|
||||
// outputted bit calls the readcb, and subsequent chunks just go into
|
||||
// the read buffer, and will cause it to emit 'readable' if necessary.
|
||||
//
|
||||
// This way, back-pressure is actually determined by the reading side,
|
||||
// since _read has to be called to start processing a new chunk. However,
|
||||
// a pathological inflate type of transform can cause excessive buffering
|
||||
// here. For example, imagine a stream where every byte of input is
|
||||
// interpreted as an integer from 0-255, and then results in that many
|
||||
// bytes of output. Writing the 4 bytes {ff,ff,ff,ff} would result in
|
||||
// 1kb of data being output. In this case, you could write a very small
|
||||
// amount of input, and end up with a very large amount of output. In
|
||||
// such a pathological inflating mechanism, there'd be no way to tell
|
||||
// the system to stop doing the transform. A single 4MB write could
|
||||
// cause the system to run out of memory.
|
||||
//
|
||||
// However, even in such a pathological case, only a single written chunk
|
||||
// would be consumed, and then the rest would wait (un-transformed) until
|
||||
// the results of the previous transformed chunk were consumed.
|
||||
|
||||
module.exports = Transform;
|
||||
|
||||
var Duplex = require('./_stream_duplex');
|
||||
|
||||
/*<replacement>*/
|
||||
var util = require('core-util-is');
|
||||
util.inherits = require('inherits');
|
||||
/*</replacement>*/
|
||||
|
||||
util.inherits(Transform, Duplex);
|
||||
|
||||
|
||||
function TransformState(options, stream) {
|
||||
this.afterTransform = function(er, data) {
|
||||
return afterTransform(stream, er, data);
|
||||
};
|
||||
|
||||
this.needTransform = false;
|
||||
this.transforming = false;
|
||||
this.writecb = null;
|
||||
this.writechunk = null;
|
||||
}
|
||||
|
||||
function afterTransform(stream, er, data) {
|
||||
var ts = stream._transformState;
|
||||
ts.transforming = false;
|
||||
|
||||
var cb = ts.writecb;
|
||||
|
||||
if (!cb)
|
||||
return stream.emit('error', new Error('no writecb in Transform class'));
|
||||
|
||||
ts.writechunk = null;
|
||||
ts.writecb = null;
|
||||
|
||||
if (!util.isNullOrUndefined(data))
|
||||
stream.push(data);
|
||||
|
||||
if (cb)
|
||||
cb(er);
|
||||
|
||||
var rs = stream._readableState;
|
||||
rs.reading = false;
|
||||
if (rs.needReadable || rs.length < rs.highWaterMark) {
|
||||
stream._read(rs.highWaterMark);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function Transform(options) {
|
||||
if (!(this instanceof Transform))
|
||||
return new Transform(options);
|
||||
|
||||
Duplex.call(this, options);
|
||||
|
||||
this._transformState = new TransformState(options, this);
|
||||
|
||||
// when the writable side finishes, then flush out anything remaining.
|
||||
var stream = this;
|
||||
|
||||
// start out asking for a readable event once data is transformed.
|
||||
this._readableState.needReadable = true;
|
||||
|
||||
// we have implemented the _read method, and done the other things
|
||||
// that Readable wants before the first _read call, so unset the
|
||||
// sync guard flag.
|
||||
this._readableState.sync = false;
|
||||
|
||||
this.once('prefinish', function() {
|
||||
if (util.isFunction(this._flush))
|
||||
this._flush(function(er) {
|
||||
done(stream, er);
|
||||
});
|
||||
else
|
||||
done(stream);
|
||||
});
|
||||
}
|
||||
|
||||
Transform.prototype.push = function(chunk, encoding) {
|
||||
this._transformState.needTransform = false;
|
||||
return Duplex.prototype.push.call(this, chunk, encoding);
|
||||
};
|
||||
|
||||
// This is the part where you do stuff!
|
||||
// override this function in implementation classes.
|
||||
// 'chunk' is an input chunk.
|
||||
//
|
||||
// Call `push(newChunk)` to pass along transformed output
|
||||
// to the readable side. You may call 'push' zero or more times.
|
||||
//
|
||||
// Call `cb(err)` when you are done with this chunk. If you pass
|
||||
// an error, then that'll put the hurt on the whole operation. If you
|
||||
// never call cb(), then you'll never get another chunk.
|
||||
Transform.prototype._transform = function(chunk, encoding, cb) {
|
||||
throw new Error('not implemented');
|
||||
};
|
||||
|
||||
Transform.prototype._write = function(chunk, encoding, cb) {
|
||||
var ts = this._transformState;
|
||||
ts.writecb = cb;
|
||||
ts.writechunk = chunk;
|
||||
ts.writeencoding = encoding;
|
||||
if (!ts.transforming) {
|
||||
var rs = this._readableState;
|
||||
if (ts.needTransform ||
|
||||
rs.needReadable ||
|
||||
rs.length < rs.highWaterMark)
|
||||
this._read(rs.highWaterMark);
|
||||
}
|
||||
};
|
||||
|
||||
// Doesn't matter what the args are here.
|
||||
// _transform does all the work.
|
||||
// That we got here means that the readable side wants more data.
|
||||
Transform.prototype._read = function(n) {
|
||||
var ts = this._transformState;
|
||||
|
||||
if (!util.isNull(ts.writechunk) && ts.writecb && !ts.transforming) {
|
||||
ts.transforming = true;
|
||||
this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform);
|
||||
} else {
|
||||
// mark that we need a transform, so that any data that comes in
|
||||
// will get processed, now that we've asked for it.
|
||||
ts.needTransform = true;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
function done(stream, er) {
|
||||
if (er)
|
||||
return stream.emit('error', er);
|
||||
|
||||
// if there's nothing in the write buffer, then that means
|
||||
// that nothing more will ever be provided
|
||||
var ws = stream._writableState;
|
||||
var ts = stream._transformState;
|
||||
|
||||
if (ws.length)
|
||||
throw new Error('calling transform done when ws.length != 0');
|
||||
|
||||
if (ts.transforming)
|
||||
throw new Error('calling transform done when still transforming');
|
||||
|
||||
return stream.push(null);
|
||||
}
|
477
express-server/node_modules/busboy/node_modules/readable-stream/lib/_stream_writable.js
generated
vendored
Normal file
477
express-server/node_modules/busboy/node_modules/readable-stream/lib/_stream_writable.js
generated
vendored
Normal file
@ -0,0 +1,477 @@
|
||||
// Copyright Joyent, Inc. and other Node contributors.
|
||||
//
|
||||
// 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.
|
||||
|
||||
// A bit simpler than readable streams.
|
||||
// Implement an async ._write(chunk, cb), and it'll handle all
|
||||
// the drain event emission and buffering.
|
||||
|
||||
module.exports = Writable;
|
||||
|
||||
/*<replacement>*/
|
||||
var Buffer = require('buffer').Buffer;
|
||||
/*</replacement>*/
|
||||
|
||||
Writable.WritableState = WritableState;
|
||||
|
||||
|
||||
/*<replacement>*/
|
||||
var util = require('core-util-is');
|
||||
util.inherits = require('inherits');
|
||||
/*</replacement>*/
|
||||
|
||||
var Stream = require('stream');
|
||||
|
||||
util.inherits(Writable, Stream);
|
||||
|
||||
function WriteReq(chunk, encoding, cb) {
|
||||
this.chunk = chunk;
|
||||
this.encoding = encoding;
|
||||
this.callback = cb;
|
||||
}
|
||||
|
||||
function WritableState(options, stream) {
|
||||
var Duplex = require('./_stream_duplex');
|
||||
|
||||
options = options || {};
|
||||
|
||||
// the point at which write() starts returning false
|
||||
// Note: 0 is a valid value, means that we always return false if
|
||||
// the entire buffer is not flushed immediately on write()
|
||||
var hwm = options.highWaterMark;
|
||||
var defaultHwm = options.objectMode ? 16 : 16 * 1024;
|
||||
this.highWaterMark = (hwm || hwm === 0) ? hwm : defaultHwm;
|
||||
|
||||
// object stream flag to indicate whether or not this stream
|
||||
// contains buffers or objects.
|
||||
this.objectMode = !!options.objectMode;
|
||||
|
||||
if (stream instanceof Duplex)
|
||||
this.objectMode = this.objectMode || !!options.writableObjectMode;
|
||||
|
||||
// cast to ints.
|
||||
this.highWaterMark = ~~this.highWaterMark;
|
||||
|
||||
this.needDrain = false;
|
||||
// at the start of calling end()
|
||||
this.ending = false;
|
||||
// when end() has been called, and returned
|
||||
this.ended = false;
|
||||
// when 'finish' is emitted
|
||||
this.finished = false;
|
||||
|
||||
// should we decode strings into buffers before passing to _write?
|
||||
// this is here so that some node-core streams can optimize string
|
||||
// handling at a lower level.
|
||||
var noDecode = options.decodeStrings === false;
|
||||
this.decodeStrings = !noDecode;
|
||||
|
||||
// Crypto is kind of old and crusty. Historically, its default string
|
||||
// encoding is 'binary' so we have to make this configurable.
|
||||
// Everything else in the universe uses 'utf8', though.
|
||||
this.defaultEncoding = options.defaultEncoding || 'utf8';
|
||||
|
||||
// not an actual buffer we keep track of, but a measurement
|
||||
// of how much we're waiting to get pushed to some underlying
|
||||
// socket or file.
|
||||
this.length = 0;
|
||||
|
||||
// a flag to see when we're in the middle of a write.
|
||||
this.writing = false;
|
||||
|
||||
// when true all writes will be buffered until .uncork() call
|
||||
this.corked = 0;
|
||||
|
||||
// a flag to be able to tell if the onwrite cb is called immediately,
|
||||
// or on a later tick. We set this to true at first, because any
|
||||
// actions that shouldn't happen until "later" should generally also
|
||||
// not happen before the first write call.
|
||||
this.sync = true;
|
||||
|
||||
// a flag to know if we're processing previously buffered items, which
|
||||
// may call the _write() callback in the same tick, so that we don't
|
||||
// end up in an overlapped onwrite situation.
|
||||
this.bufferProcessing = false;
|
||||
|
||||
// the callback that's passed to _write(chunk,cb)
|
||||
this.onwrite = function(er) {
|
||||
onwrite(stream, er);
|
||||
};
|
||||
|
||||
// the callback that the user supplies to write(chunk,encoding,cb)
|
||||
this.writecb = null;
|
||||
|
||||
// the amount that is being written when _write is called.
|
||||
this.writelen = 0;
|
||||
|
||||
this.buffer = [];
|
||||
|
||||
// number of pending user-supplied write callbacks
|
||||
// this must be 0 before 'finish' can be emitted
|
||||
this.pendingcb = 0;
|
||||
|
||||
// emit prefinish if the only thing we're waiting for is _write cbs
|
||||
// This is relevant for synchronous Transform streams
|
||||
this.prefinished = false;
|
||||
|
||||
// True if the error was already emitted and should not be thrown again
|
||||
this.errorEmitted = false;
|
||||
}
|
||||
|
||||
function Writable(options) {
|
||||
var Duplex = require('./_stream_duplex');
|
||||
|
||||
// Writable ctor is applied to Duplexes, though they're not
|
||||
// instanceof Writable, they're instanceof Readable.
|
||||
if (!(this instanceof Writable) && !(this instanceof Duplex))
|
||||
return new Writable(options);
|
||||
|
||||
this._writableState = new WritableState(options, this);
|
||||
|
||||
// legacy.
|
||||
this.writable = true;
|
||||
|
||||
Stream.call(this);
|
||||
}
|
||||
|
||||
// Otherwise people can pipe Writable streams, which is just wrong.
|
||||
Writable.prototype.pipe = function() {
|
||||
this.emit('error', new Error('Cannot pipe. Not readable.'));
|
||||
};
|
||||
|
||||
|
||||
function writeAfterEnd(stream, state, cb) {
|
||||
var er = new Error('write after end');
|
||||
// TODO: defer error events consistently everywhere, not just the cb
|
||||
stream.emit('error', er);
|
||||
process.nextTick(function() {
|
||||
cb(er);
|
||||
});
|
||||
}
|
||||
|
||||
// If we get something that is not a buffer, string, null, or undefined,
|
||||
// and we're not in objectMode, then that's an error.
|
||||
// Otherwise stream chunks are all considered to be of length=1, and the
|
||||
// watermarks determine how many objects to keep in the buffer, rather than
|
||||
// how many bytes or characters.
|
||||
function validChunk(stream, state, chunk, cb) {
|
||||
var valid = true;
|
||||
if (!util.isBuffer(chunk) &&
|
||||
!util.isString(chunk) &&
|
||||
!util.isNullOrUndefined(chunk) &&
|
||||
!state.objectMode) {
|
||||
var er = new TypeError('Invalid non-string/buffer chunk');
|
||||
stream.emit('error', er);
|
||||
process.nextTick(function() {
|
||||
cb(er);
|
||||
});
|
||||
valid = false;
|
||||
}
|
||||
return valid;
|
||||
}
|
||||
|
||||
Writable.prototype.write = function(chunk, encoding, cb) {
|
||||
var state = this._writableState;
|
||||
var ret = false;
|
||||
|
||||
if (util.isFunction(encoding)) {
|
||||
cb = encoding;
|
||||
encoding = null;
|
||||
}
|
||||
|
||||
if (util.isBuffer(chunk))
|
||||
encoding = 'buffer';
|
||||
else if (!encoding)
|
||||
encoding = state.defaultEncoding;
|
||||
|
||||
if (!util.isFunction(cb))
|
||||
cb = function() {};
|
||||
|
||||
if (state.ended)
|
||||
writeAfterEnd(this, state, cb);
|
||||
else if (validChunk(this, state, chunk, cb)) {
|
||||
state.pendingcb++;
|
||||
ret = writeOrBuffer(this, state, chunk, encoding, cb);
|
||||
}
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
Writable.prototype.cork = function() {
|
||||
var state = this._writableState;
|
||||
|
||||
state.corked++;
|
||||
};
|
||||
|
||||
Writable.prototype.uncork = function() {
|
||||
var state = this._writableState;
|
||||
|
||||
if (state.corked) {
|
||||
state.corked--;
|
||||
|
||||
if (!state.writing &&
|
||||
!state.corked &&
|
||||
!state.finished &&
|
||||
!state.bufferProcessing &&
|
||||
state.buffer.length)
|
||||
clearBuffer(this, state);
|
||||
}
|
||||
};
|
||||
|
||||
function decodeChunk(state, chunk, encoding) {
|
||||
if (!state.objectMode &&
|
||||
state.decodeStrings !== false &&
|
||||
util.isString(chunk)) {
|
||||
chunk = new Buffer(chunk, encoding);
|
||||
}
|
||||
return chunk;
|
||||
}
|
||||
|
||||
// if we're already writing something, then just put this
|
||||
// in the queue, and wait our turn. Otherwise, call _write
|
||||
// If we return false, then we need a drain event, so set that flag.
|
||||
function writeOrBuffer(stream, state, chunk, encoding, cb) {
|
||||
chunk = decodeChunk(state, chunk, encoding);
|
||||
if (util.isBuffer(chunk))
|
||||
encoding = 'buffer';
|
||||
var len = state.objectMode ? 1 : chunk.length;
|
||||
|
||||
state.length += len;
|
||||
|
||||
var ret = state.length < state.highWaterMark;
|
||||
// we must ensure that previous needDrain will not be reset to false.
|
||||
if (!ret)
|
||||
state.needDrain = true;
|
||||
|
||||
if (state.writing || state.corked)
|
||||
state.buffer.push(new WriteReq(chunk, encoding, cb));
|
||||
else
|
||||
doWrite(stream, state, false, len, chunk, encoding, cb);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
function doWrite(stream, state, writev, len, chunk, encoding, cb) {
|
||||
state.writelen = len;
|
||||
state.writecb = cb;
|
||||
state.writing = true;
|
||||
state.sync = true;
|
||||
if (writev)
|
||||
stream._writev(chunk, state.onwrite);
|
||||
else
|
||||
stream._write(chunk, encoding, state.onwrite);
|
||||
state.sync = false;
|
||||
}
|
||||
|
||||
function onwriteError(stream, state, sync, er, cb) {
|
||||
if (sync)
|
||||
process.nextTick(function() {
|
||||
state.pendingcb--;
|
||||
cb(er);
|
||||
});
|
||||
else {
|
||||
state.pendingcb--;
|
||||
cb(er);
|
||||
}
|
||||
|
||||
stream._writableState.errorEmitted = true;
|
||||
stream.emit('error', er);
|
||||
}
|
||||
|
||||
function onwriteStateUpdate(state) {
|
||||
state.writing = false;
|
||||
state.writecb = null;
|
||||
state.length -= state.writelen;
|
||||
state.writelen = 0;
|
||||
}
|
||||
|
||||
function onwrite(stream, er) {
|
||||
var state = stream._writableState;
|
||||
var sync = state.sync;
|
||||
var cb = state.writecb;
|
||||
|
||||
onwriteStateUpdate(state);
|
||||
|
||||
if (er)
|
||||
onwriteError(stream, state, sync, er, cb);
|
||||
else {
|
||||
// Check if we're actually ready to finish, but don't emit yet
|
||||
var finished = needFinish(stream, state);
|
||||
|
||||
if (!finished &&
|
||||
!state.corked &&
|
||||
!state.bufferProcessing &&
|
||||
state.buffer.length) {
|
||||
clearBuffer(stream, state);
|
||||
}
|
||||
|
||||
if (sync) {
|
||||
process.nextTick(function() {
|
||||
afterWrite(stream, state, finished, cb);
|
||||
});
|
||||
} else {
|
||||
afterWrite(stream, state, finished, cb);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function afterWrite(stream, state, finished, cb) {
|
||||
if (!finished)
|
||||
onwriteDrain(stream, state);
|
||||
state.pendingcb--;
|
||||
cb();
|
||||
finishMaybe(stream, state);
|
||||
}
|
||||
|
||||
// Must force callback to be called on nextTick, so that we don't
|
||||
// emit 'drain' before the write() consumer gets the 'false' return
|
||||
// value, and has a chance to attach a 'drain' listener.
|
||||
function onwriteDrain(stream, state) {
|
||||
if (state.length === 0 && state.needDrain) {
|
||||
state.needDrain = false;
|
||||
stream.emit('drain');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// if there's something in the buffer waiting, then process it
|
||||
function clearBuffer(stream, state) {
|
||||
state.bufferProcessing = true;
|
||||
|
||||
if (stream._writev && state.buffer.length > 1) {
|
||||
// Fast case, write everything using _writev()
|
||||
var cbs = [];
|
||||
for (var c = 0; c < state.buffer.length; c++)
|
||||
cbs.push(state.buffer[c].callback);
|
||||
|
||||
// count the one we are adding, as well.
|
||||
// TODO(isaacs) clean this up
|
||||
state.pendingcb++;
|
||||
doWrite(stream, state, true, state.length, state.buffer, '', function(err) {
|
||||
for (var i = 0; i < cbs.length; i++) {
|
||||
state.pendingcb--;
|
||||
cbs[i](err);
|
||||
}
|
||||
});
|
||||
|
||||
// Clear buffer
|
||||
state.buffer = [];
|
||||
} else {
|
||||
// Slow case, write chunks one-by-one
|
||||
for (var c = 0; c < state.buffer.length; c++) {
|
||||
var entry = state.buffer[c];
|
||||
var chunk = entry.chunk;
|
||||
var encoding = entry.encoding;
|
||||
var cb = entry.callback;
|
||||
var len = state.objectMode ? 1 : chunk.length;
|
||||
|
||||
doWrite(stream, state, false, len, chunk, encoding, cb);
|
||||
|
||||
// if we didn't call the onwrite immediately, then
|
||||
// it means that we need to wait until it does.
|
||||
// also, that means that the chunk and cb are currently
|
||||
// being processed, so move the buffer counter past them.
|
||||
if (state.writing) {
|
||||
c++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (c < state.buffer.length)
|
||||
state.buffer = state.buffer.slice(c);
|
||||
else
|
||||
state.buffer.length = 0;
|
||||
}
|
||||
|
||||
state.bufferProcessing = false;
|
||||
}
|
||||
|
||||
Writable.prototype._write = function(chunk, encoding, cb) {
|
||||
cb(new Error('not implemented'));
|
||||
|
||||
};
|
||||
|
||||
Writable.prototype._writev = null;
|
||||
|
||||
Writable.prototype.end = function(chunk, encoding, cb) {
|
||||
var state = this._writableState;
|
||||
|
||||
if (util.isFunction(chunk)) {
|
||||
cb = chunk;
|
||||
chunk = null;
|
||||
encoding = null;
|
||||
} else if (util.isFunction(encoding)) {
|
||||
cb = encoding;
|
||||
encoding = null;
|
||||
}
|
||||
|
||||
if (!util.isNullOrUndefined(chunk))
|
||||
this.write(chunk, encoding);
|
||||
|
||||
// .end() fully uncorks
|
||||
if (state.corked) {
|
||||
state.corked = 1;
|
||||
this.uncork();
|
||||
}
|
||||
|
||||
// ignore unnecessary end() calls.
|
||||
if (!state.ending && !state.finished)
|
||||
endWritable(this, state, cb);
|
||||
};
|
||||
|
||||
|
||||
function needFinish(stream, state) {
|
||||
return (state.ending &&
|
||||
state.length === 0 &&
|
||||
!state.finished &&
|
||||
!state.writing);
|
||||
}
|
||||
|
||||
function prefinish(stream, state) {
|
||||
if (!state.prefinished) {
|
||||
state.prefinished = true;
|
||||
stream.emit('prefinish');
|
||||
}
|
||||
}
|
||||
|
||||
function finishMaybe(stream, state) {
|
||||
var need = needFinish(stream, state);
|
||||
if (need) {
|
||||
if (state.pendingcb === 0) {
|
||||
prefinish(stream, state);
|
||||
state.finished = true;
|
||||
stream.emit('finish');
|
||||
} else
|
||||
prefinish(stream, state);
|
||||
}
|
||||
return need;
|
||||
}
|
||||
|
||||
function endWritable(stream, state, cb) {
|
||||
state.ending = true;
|
||||
finishMaybe(stream, state);
|
||||
if (cb) {
|
||||
if (state.finished)
|
||||
process.nextTick(cb);
|
||||
else
|
||||
stream.once('finish', cb);
|
||||
}
|
||||
state.ended = true;
|
||||
}
|
65
express-server/node_modules/busboy/node_modules/readable-stream/package.json
generated
vendored
Normal file
65
express-server/node_modules/busboy/node_modules/readable-stream/package.json
generated
vendored
Normal file
@ -0,0 +1,65 @@
|
||||
{
|
||||
"_from": "readable-stream@1.1.x",
|
||||
"_id": "readable-stream@1.1.14",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=",
|
||||
"_location": "/busboy/readable-stream",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "readable-stream@1.1.x",
|
||||
"name": "readable-stream",
|
||||
"escapedName": "readable-stream",
|
||||
"rawSpec": "1.1.x",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "1.1.x"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/busboy"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz",
|
||||
"_shasum": "7cf4c54ef648e3813084c636dd2079e166c081d9",
|
||||
"_spec": "readable-stream@1.1.x",
|
||||
"_where": "D:\\5CHITM\\Diplomarbeit\\repos\\SmartShopper\\express-server\\node_modules\\busboy",
|
||||
"author": {
|
||||
"name": "Isaac Z. Schlueter",
|
||||
"email": "i@izs.me",
|
||||
"url": "http://blog.izs.me/"
|
||||
},
|
||||
"browser": {
|
||||
"util": false
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/isaacs/readable-stream/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"core-util-is": "~1.0.0",
|
||||
"inherits": "~2.0.1",
|
||||
"isarray": "0.0.1",
|
||||
"string_decoder": "~0.10.x"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "Streams3, a user-land copy of the stream library from Node.js v0.11.x",
|
||||
"devDependencies": {
|
||||
"tap": "~0.2.6"
|
||||
},
|
||||
"homepage": "https://github.com/isaacs/readable-stream#readme",
|
||||
"keywords": [
|
||||
"readable",
|
||||
"stream",
|
||||
"pipe"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "readable.js",
|
||||
"name": "readable-stream",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/isaacs/readable-stream.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "tap test/simple/*.js"
|
||||
},
|
||||
"version": "1.1.14"
|
||||
}
|
1
express-server/node_modules/busboy/node_modules/readable-stream/passthrough.js
generated
vendored
Normal file
1
express-server/node_modules/busboy/node_modules/readable-stream/passthrough.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
module.exports = require("./lib/_stream_passthrough.js")
|
10
express-server/node_modules/busboy/node_modules/readable-stream/readable.js
generated
vendored
Normal file
10
express-server/node_modules/busboy/node_modules/readable-stream/readable.js
generated
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
exports = module.exports = require('./lib/_stream_readable.js');
|
||||
exports.Stream = require('stream');
|
||||
exports.Readable = exports;
|
||||
exports.Writable = require('./lib/_stream_writable.js');
|
||||
exports.Duplex = require('./lib/_stream_duplex.js');
|
||||
exports.Transform = require('./lib/_stream_transform.js');
|
||||
exports.PassThrough = require('./lib/_stream_passthrough.js');
|
||||
if (!process.browser && process.env.READABLE_STREAM === 'disable') {
|
||||
module.exports = require('stream');
|
||||
}
|
1
express-server/node_modules/busboy/node_modules/readable-stream/transform.js
generated
vendored
Normal file
1
express-server/node_modules/busboy/node_modules/readable-stream/transform.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
module.exports = require("./lib/_stream_transform.js")
|
1
express-server/node_modules/busboy/node_modules/readable-stream/writable.js
generated
vendored
Normal file
1
express-server/node_modules/busboy/node_modules/readable-stream/writable.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
module.exports = require("./lib/_stream_writable.js")
|
70
express-server/node_modules/busboy/package.json
generated
vendored
Normal file
70
express-server/node_modules/busboy/package.json
generated
vendored
Normal file
@ -0,0 +1,70 @@
|
||||
{
|
||||
"_from": "busboy@^0.2.14",
|
||||
"_id": "busboy@0.2.14",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-bCpiLvz0fFe7vh4qnDetNseSVFM=",
|
||||
"_location": "/busboy",
|
||||
"_phantomChildren": {
|
||||
"core-util-is": "1.0.2",
|
||||
"inherits": "2.0.3",
|
||||
"isarray": "0.0.1",
|
||||
"string_decoder": "0.10.31"
|
||||
},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "busboy@^0.2.14",
|
||||
"name": "busboy",
|
||||
"escapedName": "busboy",
|
||||
"rawSpec": "^0.2.14",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^0.2.14"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/express-fileupload"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/busboy/-/busboy-0.2.14.tgz",
|
||||
"_shasum": "6c2a622efcf47c57bbbe1e2a9c37ad36c7925453",
|
||||
"_spec": "busboy@^0.2.14",
|
||||
"_where": "D:\\5CHITM\\Diplomarbeit\\repos\\SmartShopper\\express-server\\node_modules\\express-fileupload",
|
||||
"author": {
|
||||
"name": "Brian White",
|
||||
"email": "mscdex@mscdex.net"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/mscdex/busboy/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"dicer": "0.2.5",
|
||||
"readable-stream": "1.1.x"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "A streaming parser for HTML form data for node.js",
|
||||
"engines": {
|
||||
"node": ">=0.8.0"
|
||||
},
|
||||
"homepage": "https://github.com/mscdex/busboy#readme",
|
||||
"keywords": [
|
||||
"uploads",
|
||||
"forms",
|
||||
"multipart",
|
||||
"form-data"
|
||||
],
|
||||
"licenses": [
|
||||
{
|
||||
"type": "MIT",
|
||||
"url": "http://github.com/mscdex/busboy/raw/master/LICENSE"
|
||||
}
|
||||
],
|
||||
"main": "./lib/main",
|
||||
"name": "busboy",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+ssh://git@github.com/mscdex/busboy.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "node test/test.js"
|
||||
},
|
||||
"version": "0.2.14"
|
||||
}
|
343
express-server/node_modules/busboy/test/test-types-multipart.js
generated
vendored
Normal file
343
express-server/node_modules/busboy/test/test-types-multipart.js
generated
vendored
Normal file
@ -0,0 +1,343 @@
|
||||
var Busboy = require('..');
|
||||
|
||||
var path = require('path'),
|
||||
inspect = require('util').inspect,
|
||||
assert = require('assert');
|
||||
|
||||
var EMPTY_FN = function() {};
|
||||
|
||||
var t = 0,
|
||||
group = path.basename(__filename, '.js') + '/';
|
||||
var tests = [
|
||||
{ source: [
|
||||
['-----------------------------paZqsnEHRufoShdX6fh0lUhXBP4k',
|
||||
'Content-Disposition: form-data; name="file_name_0"',
|
||||
'',
|
||||
'super alpha file',
|
||||
'-----------------------------paZqsnEHRufoShdX6fh0lUhXBP4k',
|
||||
'Content-Disposition: form-data; name="file_name_1"',
|
||||
'',
|
||||
'super beta file',
|
||||
'-----------------------------paZqsnEHRufoShdX6fh0lUhXBP4k',
|
||||
'Content-Disposition: form-data; name="upload_file_0"; filename="1k_a.dat"',
|
||||
'Content-Type: application/octet-stream',
|
||||
'',
|
||||
'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
|
||||
'-----------------------------paZqsnEHRufoShdX6fh0lUhXBP4k',
|
||||
'Content-Disposition: form-data; name="upload_file_1"; filename="1k_b.dat"',
|
||||
'Content-Type: application/octet-stream',
|
||||
'',
|
||||
'BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB',
|
||||
'-----------------------------paZqsnEHRufoShdX6fh0lUhXBP4k--'
|
||||
].join('\r\n')
|
||||
],
|
||||
boundary: '---------------------------paZqsnEHRufoShdX6fh0lUhXBP4k',
|
||||
expected: [
|
||||
['field', 'file_name_0', 'super alpha file', false, false, '7bit', 'text/plain'],
|
||||
['field', 'file_name_1', 'super beta file', false, false, '7bit', 'text/plain'],
|
||||
['file', 'upload_file_0', 1023, 0, '1k_a.dat', '7bit', 'application/octet-stream'],
|
||||
['file', 'upload_file_1', 1023, 0, '1k_b.dat', '7bit', 'application/octet-stream']
|
||||
],
|
||||
what: 'Fields and files'
|
||||
},
|
||||
{ source: [
|
||||
['------WebKitFormBoundaryTB2MiQ36fnSJlrhY',
|
||||
'Content-Disposition: form-data; name="cont"',
|
||||
'',
|
||||
'some random content',
|
||||
'------WebKitFormBoundaryTB2MiQ36fnSJlrhY',
|
||||
'Content-Disposition: form-data; name="pass"',
|
||||
'',
|
||||
'some random pass',
|
||||
'------WebKitFormBoundaryTB2MiQ36fnSJlrhY',
|
||||
'Content-Disposition: form-data; name="bit"',
|
||||
'',
|
||||
'2',
|
||||
'------WebKitFormBoundaryTB2MiQ36fnSJlrhY--'
|
||||
].join('\r\n')
|
||||
],
|
||||
boundary: '----WebKitFormBoundaryTB2MiQ36fnSJlrhY',
|
||||
expected: [
|
||||
['field', 'cont', 'some random content', false, false, '7bit', 'text/plain'],
|
||||
['field', 'pass', 'some random pass', false, false, '7bit', 'text/plain'],
|
||||
['field', 'bit', '2', false, false, '7bit', 'text/plain']
|
||||
],
|
||||
what: 'Fields only'
|
||||
},
|
||||
{ source: [
|
||||
''
|
||||
],
|
||||
boundary: '----WebKitFormBoundaryTB2MiQ36fnSJlrhY',
|
||||
expected: [],
|
||||
what: 'No fields and no files'
|
||||
},
|
||||
{ source: [
|
||||
['-----------------------------paZqsnEHRufoShdX6fh0lUhXBP4k',
|
||||
'Content-Disposition: form-data; name="file_name_0"',
|
||||
'',
|
||||
'super alpha file',
|
||||
'-----------------------------paZqsnEHRufoShdX6fh0lUhXBP4k',
|
||||
'Content-Disposition: form-data; name="upload_file_0"; filename="1k_a.dat"',
|
||||
'Content-Type: application/octet-stream',
|
||||
'',
|
||||
'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
|
||||
'-----------------------------paZqsnEHRufoShdX6fh0lUhXBP4k--'
|
||||
].join('\r\n')
|
||||
],
|
||||
boundary: '---------------------------paZqsnEHRufoShdX6fh0lUhXBP4k',
|
||||
limits: {
|
||||
fileSize: 13,
|
||||
fieldSize: 5
|
||||
},
|
||||
expected: [
|
||||
['field', 'file_name_0', 'super', false, true, '7bit', 'text/plain'],
|
||||
['file', 'upload_file_0', 13, 2, '1k_a.dat', '7bit', 'application/octet-stream']
|
||||
],
|
||||
what: 'Fields and files (limits)'
|
||||
},
|
||||
{ source: [
|
||||
['-----------------------------paZqsnEHRufoShdX6fh0lUhXBP4k',
|
||||
'Content-Disposition: form-data; name="file_name_0"',
|
||||
'',
|
||||
'super alpha file',
|
||||
'-----------------------------paZqsnEHRufoShdX6fh0lUhXBP4k',
|
||||
'Content-Disposition: form-data; name="upload_file_0"; filename="1k_a.dat"',
|
||||
'Content-Type: application/octet-stream',
|
||||
'',
|
||||
'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
|
||||
'-----------------------------paZqsnEHRufoShdX6fh0lUhXBP4k--'
|
||||
].join('\r\n')
|
||||
],
|
||||
boundary: '---------------------------paZqsnEHRufoShdX6fh0lUhXBP4k',
|
||||
limits: {
|
||||
files: 0
|
||||
},
|
||||
expected: [
|
||||
['field', 'file_name_0', 'super alpha file', false, false, '7bit', 'text/plain']
|
||||
],
|
||||
what: 'Fields and files (limits: 0 files)'
|
||||
},
|
||||
{ source: [
|
||||
['-----------------------------paZqsnEHRufoShdX6fh0lUhXBP4k',
|
||||
'Content-Disposition: form-data; name="file_name_0"',
|
||||
'',
|
||||
'super alpha file',
|
||||
'-----------------------------paZqsnEHRufoShdX6fh0lUhXBP4k',
|
||||
'Content-Disposition: form-data; name="file_name_1"',
|
||||
'',
|
||||
'super beta file',
|
||||
'-----------------------------paZqsnEHRufoShdX6fh0lUhXBP4k',
|
||||
'Content-Disposition: form-data; name="upload_file_0"; filename="1k_a.dat"',
|
||||
'Content-Type: application/octet-stream',
|
||||
'',
|
||||
'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
|
||||
'-----------------------------paZqsnEHRufoShdX6fh0lUhXBP4k',
|
||||
'Content-Disposition: form-data; name="upload_file_1"; filename="1k_b.dat"',
|
||||
'Content-Type: application/octet-stream',
|
||||
'',
|
||||
'BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB',
|
||||
'-----------------------------paZqsnEHRufoShdX6fh0lUhXBP4k--'
|
||||
].join('\r\n')
|
||||
],
|
||||
boundary: '---------------------------paZqsnEHRufoShdX6fh0lUhXBP4k',
|
||||
expected: [
|
||||
['field', 'file_name_0', 'super alpha file', false, false, '7bit', 'text/plain'],
|
||||
['field', 'file_name_1', 'super beta file', false, false, '7bit', 'text/plain'],
|
||||
],
|
||||
events: ['field'],
|
||||
what: 'Fields and (ignored) files'
|
||||
},
|
||||
{ source: [
|
||||
['-----------------------------paZqsnEHRufoShdX6fh0lUhXBP4k',
|
||||
'Content-Disposition: form-data; name="upload_file_0"; filename="/tmp/1k_a.dat"',
|
||||
'Content-Type: application/octet-stream',
|
||||
'',
|
||||
'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
|
||||
'-----------------------------paZqsnEHRufoShdX6fh0lUhXBP4k',
|
||||
'Content-Disposition: form-data; name="upload_file_1"; filename="C:\\files\\1k_b.dat"',
|
||||
'Content-Type: application/octet-stream',
|
||||
'',
|
||||
'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
|
||||
'-----------------------------paZqsnEHRufoShdX6fh0lUhXBP4k',
|
||||
'Content-Disposition: form-data; name="upload_file_2"; filename="relative/1k_c.dat"',
|
||||
'Content-Type: application/octet-stream',
|
||||
'',
|
||||
'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
|
||||
'-----------------------------paZqsnEHRufoShdX6fh0lUhXBP4k--'
|
||||
].join('\r\n')
|
||||
],
|
||||
boundary: '---------------------------paZqsnEHRufoShdX6fh0lUhXBP4k',
|
||||
expected: [
|
||||
['file', 'upload_file_0', 26, 0, '1k_a.dat', '7bit', 'application/octet-stream'],
|
||||
['file', 'upload_file_1', 26, 0, '1k_b.dat', '7bit', 'application/octet-stream'],
|
||||
['file', 'upload_file_2', 26, 0, '1k_c.dat', '7bit', 'application/octet-stream']
|
||||
],
|
||||
what: 'Files with filenames containing paths'
|
||||
},
|
||||
{ source: [
|
||||
['-----------------------------paZqsnEHRufoShdX6fh0lUhXBP4k',
|
||||
'Content-Disposition: form-data; name="upload_file_0"; filename="/absolute/1k_a.dat"',
|
||||
'Content-Type: application/octet-stream',
|
||||
'',
|
||||
'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
|
||||
'-----------------------------paZqsnEHRufoShdX6fh0lUhXBP4k',
|
||||
'Content-Disposition: form-data; name="upload_file_1"; filename="C:\\absolute\\1k_b.dat"',
|
||||
'Content-Type: application/octet-stream',
|
||||
'',
|
||||
'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
|
||||
'-----------------------------paZqsnEHRufoShdX6fh0lUhXBP4k',
|
||||
'Content-Disposition: form-data; name="upload_file_2"; filename="relative/1k_c.dat"',
|
||||
'Content-Type: application/octet-stream',
|
||||
'',
|
||||
'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
|
||||
'-----------------------------paZqsnEHRufoShdX6fh0lUhXBP4k--'
|
||||
].join('\r\n')
|
||||
],
|
||||
boundary: '---------------------------paZqsnEHRufoShdX6fh0lUhXBP4k',
|
||||
preservePath: true,
|
||||
expected: [
|
||||
['file', 'upload_file_0', 26, 0, '/absolute/1k_a.dat', '7bit', 'application/octet-stream'],
|
||||
['file', 'upload_file_1', 26, 0, 'C:\\absolute\\1k_b.dat', '7bit', 'application/octet-stream'],
|
||||
['file', 'upload_file_2', 26, 0, 'relative/1k_c.dat', '7bit', 'application/octet-stream']
|
||||
],
|
||||
what: 'Paths to be preserved through the preservePath option'
|
||||
},
|
||||
{ source: [
|
||||
['------WebKitFormBoundaryTB2MiQ36fnSJlrhY',
|
||||
'Content-Disposition: form-data; name="cont"',
|
||||
'Content-Type: ',
|
||||
'',
|
||||
'some random content',
|
||||
'------WebKitFormBoundaryTB2MiQ36fnSJlrhY',
|
||||
'Content-Disposition: ',
|
||||
'',
|
||||
'some random pass',
|
||||
'------WebKitFormBoundaryTB2MiQ36fnSJlrhY--'
|
||||
].join('\r\n')
|
||||
],
|
||||
boundary: '----WebKitFormBoundaryTB2MiQ36fnSJlrhY',
|
||||
expected: [
|
||||
['field', 'cont', 'some random content', false, false, '7bit', 'text/plain']
|
||||
],
|
||||
what: 'Empty content-type and empty content-disposition'
|
||||
},
|
||||
{ source: [
|
||||
['--asdasdasdasd\r\n',
|
||||
'Content-Type: text/plain\r\n',
|
||||
'Content-Disposition: form-data; name="foo"\r\n',
|
||||
'\r\n',
|
||||
'asd\r\n',
|
||||
'--asdasdasdasd--'
|
||||
].join(':)')
|
||||
],
|
||||
boundary: 'asdasdasdasd',
|
||||
expected: [],
|
||||
shouldError: 'Unexpected end of multipart data',
|
||||
what: 'Stopped mid-header'
|
||||
},
|
||||
{ source: [
|
||||
['------WebKitFormBoundaryTB2MiQ36fnSJlrhY',
|
||||
'Content-Disposition: form-data; name="cont"',
|
||||
'Content-Type: application/json',
|
||||
'',
|
||||
'{}',
|
||||
'------WebKitFormBoundaryTB2MiQ36fnSJlrhY--',
|
||||
].join('\r\n')
|
||||
],
|
||||
boundary: '----WebKitFormBoundaryTB2MiQ36fnSJlrhY',
|
||||
expected: [
|
||||
['field', 'cont', '{}', false, false, '7bit', 'application/json']
|
||||
],
|
||||
what: 'content-type for fields'
|
||||
},
|
||||
{ source: [
|
||||
'------WebKitFormBoundaryTB2MiQ36fnSJlrhY--\r\n'
|
||||
],
|
||||
boundary: '----WebKitFormBoundaryTB2MiQ36fnSJlrhY',
|
||||
expected: [],
|
||||
what: 'empty form'
|
||||
}
|
||||
];
|
||||
|
||||
function next() {
|
||||
if (t === tests.length)
|
||||
return;
|
||||
|
||||
var v = tests[t];
|
||||
|
||||
var busboy = new Busboy({
|
||||
limits: v.limits,
|
||||
preservePath: v.preservePath,
|
||||
headers: {
|
||||
'content-type': 'multipart/form-data; boundary=' + v.boundary
|
||||
}
|
||||
}),
|
||||
finishes = 0,
|
||||
results = [];
|
||||
|
||||
if (v.events === undefined || v.events.indexOf('field') > -1) {
|
||||
busboy.on('field', function(key, val, keyTrunc, valTrunc, encoding, contype) {
|
||||
results.push(['field', key, val, keyTrunc, valTrunc, encoding, contype]);
|
||||
});
|
||||
}
|
||||
if (v.events === undefined || v.events.indexOf('file') > -1) {
|
||||
busboy.on('file', function(fieldname, stream, filename, encoding, mimeType) {
|
||||
var nb = 0,
|
||||
info = ['file',
|
||||
fieldname,
|
||||
nb,
|
||||
0,
|
||||
filename,
|
||||
encoding,
|
||||
mimeType];
|
||||
results.push(info);
|
||||
stream.on('data', function(d) {
|
||||
nb += d.length;
|
||||
}).on('limit', function() {
|
||||
++info[3];
|
||||
}).on('end', function() {
|
||||
info[2] = nb;
|
||||
if (stream.truncated)
|
||||
++info[3];
|
||||
});
|
||||
});
|
||||
}
|
||||
busboy.on('finish', function() {
|
||||
assert(finishes++ === 0, makeMsg(v.what, 'finish emitted multiple times'));
|
||||
assert.deepEqual(results.length,
|
||||
v.expected.length,
|
||||
makeMsg(v.what, 'Parsed result count mismatch. Saw '
|
||||
+ results.length
|
||||
+ '. Expected: ' + v.expected.length));
|
||||
|
||||
results.forEach(function(result, i) {
|
||||
assert.deepEqual(result,
|
||||
v.expected[i],
|
||||
makeMsg(v.what,
|
||||
'Result mismatch:\nParsed: ' + inspect(result)
|
||||
+ '\nExpected: ' + inspect(v.expected[i]))
|
||||
);
|
||||
});
|
||||
++t;
|
||||
next();
|
||||
}).on('error', function(err) {
|
||||
if (!v.shouldError || v.shouldError !== err.message)
|
||||
assert(false, makeMsg(v.what, 'Unexpected error: ' + err));
|
||||
});
|
||||
|
||||
v.source.forEach(function(s) {
|
||||
busboy.write(new Buffer(s, 'utf8'), EMPTY_FN);
|
||||
});
|
||||
busboy.end();
|
||||
}
|
||||
next();
|
||||
|
||||
function makeMsg(what, msg) {
|
||||
return '[' + group + what + ']: ' + msg;
|
||||
}
|
||||
|
||||
process.on('exit', function() {
|
||||
assert(t === tests.length,
|
||||
makeMsg('_exit',
|
||||
'Only finished ' + t + '/' + tests.length + ' tests'));
|
||||
});
|
183
express-server/node_modules/busboy/test/test-types-urlencoded.js
generated
vendored
Normal file
183
express-server/node_modules/busboy/test/test-types-urlencoded.js
generated
vendored
Normal file
@ -0,0 +1,183 @@
|
||||
var Busboy = require('..');
|
||||
|
||||
var path = require('path'),
|
||||
inspect = require('util').inspect,
|
||||
assert = require('assert');
|
||||
|
||||
var EMPTY_FN = function() {};
|
||||
|
||||
var t = 0,
|
||||
group = path.basename(__filename, '.js') + '/';
|
||||
|
||||
var tests = [
|
||||
{ source: ['foo'],
|
||||
expected: [['foo', '', false, false]],
|
||||
what: 'Unassigned value'
|
||||
},
|
||||
{ source: ['foo=bar'],
|
||||
expected: [['foo', 'bar', false, false]],
|
||||
what: 'Assigned value'
|
||||
},
|
||||
{ source: ['foo&bar=baz'],
|
||||
expected: [['foo', '', false, false],
|
||||
['bar', 'baz', false, false]],
|
||||
what: 'Unassigned and assigned value'
|
||||
},
|
||||
{ source: ['foo=bar&baz'],
|
||||
expected: [['foo', 'bar', false, false],
|
||||
['baz', '', false, false]],
|
||||
what: 'Assigned and unassigned value'
|
||||
},
|
||||
{ source: ['foo=bar&baz=bla'],
|
||||
expected: [['foo', 'bar', false, false],
|
||||
['baz', 'bla', false, false]],
|
||||
what: 'Two assigned values'
|
||||
},
|
||||
{ source: ['foo&bar'],
|
||||
expected: [['foo', '', false, false],
|
||||
['bar', '', false, false]],
|
||||
what: 'Two unassigned values'
|
||||
},
|
||||
{ source: ['foo&bar&'],
|
||||
expected: [['foo', '', false, false],
|
||||
['bar', '', false, false]],
|
||||
what: 'Two unassigned values and ampersand'
|
||||
},
|
||||
{ source: ['foo=bar+baz%2Bquux'],
|
||||
expected: [['foo', 'bar baz+quux', false, false]],
|
||||
what: 'Assigned value with (plus) space'
|
||||
},
|
||||
{ source: ['foo=bar%20baz%21'],
|
||||
expected: [['foo', 'bar baz!', false, false]],
|
||||
what: 'Assigned value with encoded bytes'
|
||||
},
|
||||
{ source: ['foo%20bar=baz%20bla%21'],
|
||||
expected: [['foo bar', 'baz bla!', false, false]],
|
||||
what: 'Assigned value with encoded bytes #2'
|
||||
},
|
||||
{ source: ['foo=bar%20baz%21&num=1000'],
|
||||
expected: [['foo', 'bar baz!', false, false],
|
||||
['num', '1000', false, false]],
|
||||
what: 'Two assigned values, one with encoded bytes'
|
||||
},
|
||||
{ source: ['foo=bar&baz=bla'],
|
||||
expected: [],
|
||||
what: 'Limits: zero fields',
|
||||
limits: { fields: 0 }
|
||||
},
|
||||
{ source: ['foo=bar&baz=bla'],
|
||||
expected: [['foo', 'bar', false, false]],
|
||||
what: 'Limits: one field',
|
||||
limits: { fields: 1 }
|
||||
},
|
||||
{ source: ['foo=bar&baz=bla'],
|
||||
expected: [['foo', 'bar', false, false],
|
||||
['baz', 'bla', false, false]],
|
||||
what: 'Limits: field part lengths match limits',
|
||||
limits: { fieldNameSize: 3, fieldSize: 3 }
|
||||
},
|
||||
{ source: ['foo=bar&baz=bla'],
|
||||
expected: [['fo', 'bar', true, false],
|
||||
['ba', 'bla', true, false]],
|
||||
what: 'Limits: truncated field name',
|
||||
limits: { fieldNameSize: 2 }
|
||||
},
|
||||
{ source: ['foo=bar&baz=bla'],
|
||||
expected: [['foo', 'ba', false, true],
|
||||
['baz', 'bl', false, true]],
|
||||
what: 'Limits: truncated field value',
|
||||
limits: { fieldSize: 2 }
|
||||
},
|
||||
{ source: ['foo=bar&baz=bla'],
|
||||
expected: [['fo', 'ba', true, true],
|
||||
['ba', 'bl', true, true]],
|
||||
what: 'Limits: truncated field name and value',
|
||||
limits: { fieldNameSize: 2, fieldSize: 2 }
|
||||
},
|
||||
{ source: ['foo=bar&baz=bla'],
|
||||
expected: [['fo', '', true, true],
|
||||
['ba', '', true, true]],
|
||||
what: 'Limits: truncated field name and zero value limit',
|
||||
limits: { fieldNameSize: 2, fieldSize: 0 }
|
||||
},
|
||||
{ source: ['foo=bar&baz=bla'],
|
||||
expected: [['', '', true, true],
|
||||
['', '', true, true]],
|
||||
what: 'Limits: truncated zero field name and zero value limit',
|
||||
limits: { fieldNameSize: 0, fieldSize: 0 }
|
||||
},
|
||||
{ source: ['&'],
|
||||
expected: [],
|
||||
what: 'Ampersand'
|
||||
},
|
||||
{ source: ['&&&&&'],
|
||||
expected: [],
|
||||
what: 'Many ampersands'
|
||||
},
|
||||
{ source: ['='],
|
||||
expected: [['', '', false, false]],
|
||||
what: 'Assigned value, empty name and value'
|
||||
},
|
||||
{ source: [''],
|
||||
expected: [],
|
||||
what: 'Nothing'
|
||||
},
|
||||
];
|
||||
|
||||
function next() {
|
||||
if (t === tests.length)
|
||||
return;
|
||||
|
||||
var v = tests[t];
|
||||
|
||||
var busboy = new Busboy({
|
||||
limits: v.limits,
|
||||
headers: {
|
||||
'content-type': 'application/x-www-form-urlencoded; charset=utf-8'
|
||||
}
|
||||
}),
|
||||
finishes = 0,
|
||||
results = [];
|
||||
|
||||
busboy.on('field', function(key, val, keyTrunc, valTrunc) {
|
||||
results.push([key, val, keyTrunc, valTrunc]);
|
||||
});
|
||||
busboy.on('file', function() {
|
||||
throw new Error(makeMsg(v.what, 'Unexpected file'));
|
||||
});
|
||||
busboy.on('finish', function() {
|
||||
assert(finishes++ === 0, makeMsg(v.what, 'finish emitted multiple times'));
|
||||
assert.deepEqual(results.length,
|
||||
v.expected.length,
|
||||
makeMsg(v.what, 'Parsed result count mismatch. Saw '
|
||||
+ results.length
|
||||
+ '. Expected: ' + v.expected.length));
|
||||
|
||||
var i = 0;
|
||||
results.forEach(function(result) {
|
||||
assert.deepEqual(result,
|
||||
v.expected[i],
|
||||
makeMsg(v.what,
|
||||
'Result mismatch:\nParsed: ' + inspect(result)
|
||||
+ '\nExpected: ' + inspect(v.expected[i]))
|
||||
);
|
||||
++i;
|
||||
});
|
||||
++t;
|
||||
next();
|
||||
});
|
||||
|
||||
v.source.forEach(function(s) {
|
||||
busboy.write(new Buffer(s, 'utf8'), EMPTY_FN);
|
||||
});
|
||||
busboy.end();
|
||||
}
|
||||
next();
|
||||
|
||||
function makeMsg(what, msg) {
|
||||
return '[' + group + what + ']: ' + msg;
|
||||
}
|
||||
|
||||
process.on('exit', function() {
|
||||
assert(t === tests.length, makeMsg('_exit', 'Only finished ' + t + '/' + tests.length + ' tests'));
|
||||
});
|
66
express-server/node_modules/busboy/test/test-utils-decoder.js
generated
vendored
Normal file
66
express-server/node_modules/busboy/test/test-utils-decoder.js
generated
vendored
Normal file
@ -0,0 +1,66 @@
|
||||
var Decoder = require('../lib/utils').Decoder;
|
||||
|
||||
var path = require('path'),
|
||||
assert = require('assert');
|
||||
|
||||
var group = path.basename(__filename, '.js') + '/';
|
||||
|
||||
[
|
||||
{ source: ['Hello world'],
|
||||
expected: 'Hello world',
|
||||
what: 'No encoded bytes'
|
||||
},
|
||||
{ source: ['Hello%20world'],
|
||||
expected: 'Hello world',
|
||||
what: 'One full encoded byte'
|
||||
},
|
||||
{ source: ['Hello%20world%21'],
|
||||
expected: 'Hello world!',
|
||||
what: 'Two full encoded bytes'
|
||||
},
|
||||
{ source: ['Hello%', '20world'],
|
||||
expected: 'Hello world',
|
||||
what: 'One full encoded byte split #1'
|
||||
},
|
||||
{ source: ['Hello%2', '0world'],
|
||||
expected: 'Hello world',
|
||||
what: 'One full encoded byte split #2'
|
||||
},
|
||||
{ source: ['Hello%20', 'world'],
|
||||
expected: 'Hello world',
|
||||
what: 'One full encoded byte (concat)'
|
||||
},
|
||||
{ source: ['Hello%2Qworld'],
|
||||
expected: 'Hello%2Qworld',
|
||||
what: 'Malformed encoded byte #1'
|
||||
},
|
||||
{ source: ['Hello%world'],
|
||||
expected: 'Hello%world',
|
||||
what: 'Malformed encoded byte #2'
|
||||
},
|
||||
{ source: ['Hello+world'],
|
||||
expected: 'Hello world',
|
||||
what: 'Plus to space'
|
||||
},
|
||||
{ source: ['Hello+world%21'],
|
||||
expected: 'Hello world!',
|
||||
what: 'Plus and encoded byte'
|
||||
},
|
||||
{ source: ['5%2B5%3D10'],
|
||||
expected: '5+5=10',
|
||||
what: 'Encoded plus'
|
||||
},
|
||||
{ source: ['5+%2B+5+%3D+10'],
|
||||
expected: '5 + 5 = 10',
|
||||
what: 'Spaces and encoded plus'
|
||||
},
|
||||
].forEach(function(v) {
|
||||
var dec = new Decoder(), result = '';
|
||||
v.source.forEach(function(s) {
|
||||
result += dec.write(s);
|
||||
});
|
||||
var msg = '[' + group + v.what + ']: decoded string mismatch.\n'
|
||||
+ 'Saw: ' + result + '\n'
|
||||
+ 'Expected: ' + v.expected;
|
||||
assert.deepEqual(result, v.expected, msg);
|
||||
});
|
96
express-server/node_modules/busboy/test/test-utils-parse-params.js
generated
vendored
Normal file
96
express-server/node_modules/busboy/test/test-utils-parse-params.js
generated
vendored
Normal file
@ -0,0 +1,96 @@
|
||||
var parseParams = require('../lib/utils').parseParams;
|
||||
|
||||
var path = require('path'),
|
||||
assert = require('assert'),
|
||||
inspect = require('util').inspect;
|
||||
|
||||
var group = path.basename(__filename, '.js') + '/';
|
||||
|
||||
[
|
||||
{ source: 'video/ogg',
|
||||
expected: ['video/ogg'],
|
||||
what: 'No parameters'
|
||||
},
|
||||
{ source: 'video/ogg;',
|
||||
expected: ['video/ogg'],
|
||||
what: 'No parameters (with separator)'
|
||||
},
|
||||
{ source: 'video/ogg; ',
|
||||
expected: ['video/ogg'],
|
||||
what: 'No parameters (with separator followed by whitespace)'
|
||||
},
|
||||
{ source: ';video/ogg',
|
||||
expected: ['', 'video/ogg'],
|
||||
what: 'Empty parameter'
|
||||
},
|
||||
{ source: 'video/*',
|
||||
expected: ['video/*'],
|
||||
what: 'Subtype with asterisk'
|
||||
},
|
||||
{ source: 'text/plain; encoding=utf8',
|
||||
expected: ['text/plain', ['encoding', 'utf8']],
|
||||
what: 'Unquoted'
|
||||
},
|
||||
{ source: 'text/plain; encoding=',
|
||||
expected: ['text/plain', ['encoding', '']],
|
||||
what: 'Unquoted empty string'
|
||||
},
|
||||
{ source: 'text/plain; encoding="utf8"',
|
||||
expected: ['text/plain', ['encoding', 'utf8']],
|
||||
what: 'Quoted'
|
||||
},
|
||||
{ source: 'text/plain; greeting="hello \\"world\\""',
|
||||
expected: ['text/plain', ['greeting', 'hello "world"']],
|
||||
what: 'Quotes within quoted'
|
||||
},
|
||||
{ source: 'text/plain; encoding=""',
|
||||
expected: ['text/plain', ['encoding', '']],
|
||||
what: 'Quoted empty string'
|
||||
},
|
||||
{ source: 'text/plain; encoding="utf8";\t foo=bar;test',
|
||||
expected: ['text/plain', ['encoding', 'utf8'], ['foo', 'bar'], 'test'],
|
||||
what: 'Multiple params with various spacing'
|
||||
},
|
||||
{ source: "text/plain; filename*=iso-8859-1'en'%A3%20rates",
|
||||
expected: ['text/plain', ['filename', '£ rates']],
|
||||
what: 'Extended parameter (RFC 5987) with language'
|
||||
},
|
||||
{ source: "text/plain; filename*=utf-8''%c2%a3%20and%20%e2%82%ac%20rates",
|
||||
expected: ['text/plain', ['filename', '£ and € rates']],
|
||||
what: 'Extended parameter (RFC 5987) without language'
|
||||
},
|
||||
{ source: "text/plain; filename*=utf-8''%E6%B5%8B%E8%AF%95%E6%96%87%E6%A1%A3",
|
||||
expected: ['text/plain', ['filename', '测试文档']],
|
||||
what: 'Extended parameter (RFC 5987) without language #2'
|
||||
},
|
||||
{ source: "text/plain; filename*=iso-8859-1'en'%A3%20rates; altfilename*=utf-8''%c2%a3%20and%20%e2%82%ac%20rates",
|
||||
expected: ['text/plain', ['filename', '£ rates'], ['altfilename', '£ and € rates']],
|
||||
what: 'Multiple extended parameters (RFC 5987) with mixed charsets'
|
||||
},
|
||||
{ source: "text/plain; filename*=iso-8859-1'en'%A3%20rates; altfilename=\"foobarbaz\"",
|
||||
expected: ['text/plain', ['filename', '£ rates'], ['altfilename', 'foobarbaz']],
|
||||
what: 'Mixed regular and extended parameters (RFC 5987)'
|
||||
},
|
||||
{ source: "text/plain; filename=\"foobarbaz\"; altfilename*=iso-8859-1'en'%A3%20rates",
|
||||
expected: ['text/plain', ['filename', 'foobarbaz'], ['altfilename', '£ rates']],
|
||||
what: 'Mixed regular and extended parameters (RFC 5987) #2'
|
||||
},
|
||||
{ source: 'text/plain; filename="C:\\folder\\test.png"',
|
||||
expected: ['text/plain', ['filename', 'C:\\folder\\test.png']],
|
||||
what: 'Unescaped backslashes should be considered backslashes'
|
||||
},
|
||||
{ source: 'text/plain; filename="John \\"Magic\\" Smith.png"',
|
||||
expected: ['text/plain', ['filename', 'John "Magic" Smith.png']],
|
||||
what: 'Escaped double-quotes should be considered double-quotes'
|
||||
},
|
||||
{ source: 'multipart/form-data; charset=utf-8; boundary=0xKhTmLbOuNdArY',
|
||||
expected: ['multipart/form-data', ['charset', 'utf-8'], ['boundary', '0xKhTmLbOuNdArY']],
|
||||
what: 'Multiple non-quoted parameters'
|
||||
},
|
||||
].forEach(function(v) {
|
||||
var result = parseParams(v.source),
|
||||
msg = '[' + group + v.what + ']: parsed parameters mismatch.\n'
|
||||
+ 'Saw: ' + inspect(result) + '\n'
|
||||
+ 'Expected: ' + inspect(v.expected);
|
||||
assert.deepEqual(result, v.expected, msg);
|
||||
});
|
4
express-server/node_modules/busboy/test/test.js
generated
vendored
Normal file
4
express-server/node_modules/busboy/test/test.js
generated
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
require('fs').readdirSync(__dirname).forEach(function(f) {
|
||||
if (f.substr(0, 5) === 'test-')
|
||||
require('./' + f);
|
||||
});
|
Reference in New Issue
Block a user