done purchases remove, ocr scan, read image
This commit is contained in:
parent
d9c3d422d7
commit
93bbf9c2cb
@ -1,5 +1,7 @@
|
||||
const { query, nonQuery } = require("../db-config/postgresql-common");
|
||||
|
||||
const stringSimilarity = require('string-similarity');
|
||||
|
||||
//Create User Info
|
||||
|
||||
async function updateUser(uid, mid) {
|
||||
@ -266,6 +268,61 @@ async function deleteItem(item_id, group_id, sl_id) {
|
||||
}
|
||||
}
|
||||
|
||||
//Move to Done Purchases (delete items from shoppinglist & move into done_purchases table)
|
||||
|
||||
async function moveDoneItems(uid, sl_id, billcontent) {
|
||||
try {
|
||||
//Get Items From Shoppinglist
|
||||
let items = await query('SELECT row_to_json("Item") AS obj FROM "Item" JOIN "Group" USING (group_id) WHERE "Group".sl_id = $1;', [sl_id]);
|
||||
let removeableItems = compareData(items, billcontent);
|
||||
|
||||
var today = new Date();
|
||||
var dd = today.getDate();
|
||||
var mm = today.getMonth()+1;
|
||||
var yyyy = today.getFullYear();
|
||||
|
||||
if(dd<10) {
|
||||
dd = '0'+dd
|
||||
}
|
||||
|
||||
if(mm<10) {
|
||||
mm = '0'+mm
|
||||
}
|
||||
|
||||
today = mm + '/' + dd + '/' + yyyy;
|
||||
|
||||
for(let item of removeableItems) {
|
||||
await nonQuery('INSERT INTO "Done_Purchase" (purchased_item_id, username, name, date, count) VALUES($1,$2,$3,$4,$5);',
|
||||
[generate_item_id(), uid, item.name, today, 1]);
|
||||
|
||||
}
|
||||
|
||||
for(let item of removeableItems) {
|
||||
await nonQuery('DELETE FROM "Item" WHERE item_id = $1 AND group_id = $2 AND sl_id = $3;', [item.item_id, item.group_id, item.sl_id]);
|
||||
console.log(item);
|
||||
|
||||
}
|
||||
|
||||
return "done"
|
||||
}
|
||||
|
||||
catch(error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
//GET Done_Purchases
|
||||
|
||||
async function getDonePurchases(uid) {
|
||||
try {
|
||||
let result = await query('SELECT row_to_json("Done_Purchase") AS obj FROM "Done_Purchase" WHERE username = $1;', [uid]);
|
||||
return result;
|
||||
}
|
||||
|
||||
catch(error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -393,7 +450,61 @@ function users_to_array(admin, members) {
|
||||
return users;
|
||||
}
|
||||
|
||||
//Compare Data
|
||||
|
||||
function compareData(listitems, doneitems) {
|
||||
|
||||
let output = [];
|
||||
|
||||
for(let item of listitems) {
|
||||
if(doneitems.includes(item.name)) {
|
||||
output.push(item);
|
||||
}
|
||||
|
||||
else if(doneitems.toUpperCase().includes(item.name.toUpperCase())) {
|
||||
output.push(item);
|
||||
}
|
||||
|
||||
else if(doneitems.toLowerCase().includes(item.name.toLowerCase())) {
|
||||
output.push(item);
|
||||
}
|
||||
|
||||
else if(probability(item.name, doneitems) > 0.3) {
|
||||
output.push(item);
|
||||
}
|
||||
|
||||
else if(probability(item.name.toUpperCase(), doneitems.toUpperCase()) > 0.3) {
|
||||
output.push(item);
|
||||
}
|
||||
|
||||
else if(probability(item.name.toLowerCase(), doneitems.toLowerCase()) > 0.3) {
|
||||
output.push(item);
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
function probability(cur_item, data) {
|
||||
|
||||
let best = 0;
|
||||
|
||||
for(let i = 0; i < data.length; i++) {
|
||||
|
||||
let prob = stringSimilarity.compareTwoStrings(cur_item, data.slice(i, i + cur_item.length));
|
||||
|
||||
if(prob > best) {
|
||||
best = prob;
|
||||
}
|
||||
}
|
||||
|
||||
return best;
|
||||
}
|
||||
|
||||
|
||||
|
||||
module.exports = {
|
||||
getShoppinglistsAdmin, getShoppinglistsShared, newShoppinglist, displayShoppinglist, deleteShoppinglist, addGroup,
|
||||
addItem, verifyInvite, createInvite, editShoppinglist, editGroup, editItem, deleteGroup, deleteItem, manInvite, updateUser
|
||||
addItem, verifyInvite, createInvite, editShoppinglist, editGroup, editItem, deleteGroup, deleteItem, manInvite, updateUser,
|
||||
moveDoneItems, getDonePurchases
|
||||
}
|
||||
|
1
express-server/node_modules/append-field/.npmignore
generated
vendored
Normal file
1
express-server/node_modules/append-field/.npmignore
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
node_modules/
|
21
express-server/node_modules/append-field/LICENSE
generated
vendored
Normal file
21
express-server/node_modules/append-field/LICENSE
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Linus Unnebäck
|
||||
|
||||
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.
|
44
express-server/node_modules/append-field/README.md
generated
vendored
Normal file
44
express-server/node_modules/append-field/README.md
generated
vendored
Normal file
@ -0,0 +1,44 @@
|
||||
# `append-field`
|
||||
|
||||
A [W3C HTML JSON forms spec](http://www.w3.org/TR/html-json-forms/) compliant
|
||||
field appender (for lack of a better name). Useful for people implementing
|
||||
`application/x-www-form-urlencoded` and `multipart/form-data` parsers.
|
||||
|
||||
It works best on objects created with `Object.create(null)`. Otherwise it might
|
||||
conflict with variables from the prototype (e.g. `hasOwnProperty`).
|
||||
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
npm install --save append-field
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```javascript
|
||||
var appendField = require('append-field')
|
||||
var obj = Object.create(null)
|
||||
|
||||
appendField(obj, 'pets[0][species]', 'Dahut')
|
||||
appendField(obj, 'pets[0][name]', 'Hypatia')
|
||||
appendField(obj, 'pets[1][species]', 'Felis Stultus')
|
||||
appendField(obj, 'pets[1][name]', 'Billie')
|
||||
|
||||
console.log(obj)
|
||||
```
|
||||
|
||||
```text
|
||||
{ pets:
|
||||
[ { species: 'Dahut', name: 'Hypatia' },
|
||||
{ species: 'Felis Stultus', name: 'Billie' } ] }
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### `appendField(store, key, value)`
|
||||
|
||||
Adds the field named `key` with the value `value` to the object `store`.
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
12
express-server/node_modules/append-field/index.js
generated
vendored
Normal file
12
express-server/node_modules/append-field/index.js
generated
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
var parsePath = require('./lib/parse-path')
|
||||
var setValue = require('./lib/set-value')
|
||||
|
||||
function appendField (store, key, value) {
|
||||
var steps = parsePath(key)
|
||||
|
||||
steps.reduce(function (context, step) {
|
||||
return setValue(context, step, context[step.key], value)
|
||||
}, store)
|
||||
}
|
||||
|
||||
module.exports = appendField
|
53
express-server/node_modules/append-field/lib/parse-path.js
generated
vendored
Normal file
53
express-server/node_modules/append-field/lib/parse-path.js
generated
vendored
Normal file
@ -0,0 +1,53 @@
|
||||
var reFirstKey = /^[^\[]*/
|
||||
var reDigitPath = /^\[(\d+)\]/
|
||||
var reNormalPath = /^\[([^\]]+)\]/
|
||||
|
||||
function parsePath (key) {
|
||||
function failure () {
|
||||
return [{ type: 'object', key: key, last: true }]
|
||||
}
|
||||
|
||||
var firstKey = reFirstKey.exec(key)[0]
|
||||
if (!firstKey) return failure()
|
||||
|
||||
var len = key.length
|
||||
var pos = firstKey.length
|
||||
var tail = { type: 'object', key: firstKey }
|
||||
var steps = [tail]
|
||||
|
||||
while (pos < len) {
|
||||
var m
|
||||
|
||||
if (key[pos] === '[' && key[pos + 1] === ']') {
|
||||
pos += 2
|
||||
tail.append = true
|
||||
if (pos !== len) return failure()
|
||||
continue
|
||||
}
|
||||
|
||||
m = reDigitPath.exec(key.substring(pos))
|
||||
if (m !== null) {
|
||||
pos += m[0].length
|
||||
tail.nextType = 'array'
|
||||
tail = { type: 'array', key: parseInt(m[1], 10) }
|
||||
steps.push(tail)
|
||||
continue
|
||||
}
|
||||
|
||||
m = reNormalPath.exec(key.substring(pos))
|
||||
if (m !== null) {
|
||||
pos += m[0].length
|
||||
tail.nextType = 'object'
|
||||
tail = { type: 'object', key: m[1] }
|
||||
steps.push(tail)
|
||||
continue
|
||||
}
|
||||
|
||||
return failure()
|
||||
}
|
||||
|
||||
tail.last = true
|
||||
return steps
|
||||
}
|
||||
|
||||
module.exports = parsePath
|
64
express-server/node_modules/append-field/lib/set-value.js
generated
vendored
Normal file
64
express-server/node_modules/append-field/lib/set-value.js
generated
vendored
Normal file
@ -0,0 +1,64 @@
|
||||
function valueType (value) {
|
||||
if (value === undefined) return 'undefined'
|
||||
if (Array.isArray(value)) return 'array'
|
||||
if (typeof value === 'object') return 'object'
|
||||
return 'scalar'
|
||||
}
|
||||
|
||||
function setLastValue (context, step, currentValue, entryValue) {
|
||||
switch (valueType(currentValue)) {
|
||||
case 'undefined':
|
||||
if (step.append) {
|
||||
context[step.key] = [entryValue]
|
||||
} else {
|
||||
context[step.key] = entryValue
|
||||
}
|
||||
break
|
||||
case 'array':
|
||||
context[step.key].push(entryValue)
|
||||
break
|
||||
case 'object':
|
||||
return setLastValue(currentValue, { type: 'object', key: '', last: true }, currentValue[''], entryValue)
|
||||
case 'scalar':
|
||||
context[step.key] = [context[step.key], entryValue]
|
||||
break
|
||||
}
|
||||
|
||||
return context
|
||||
}
|
||||
|
||||
function setValue (context, step, currentValue, entryValue) {
|
||||
if (step.last) return setLastValue(context, step, currentValue, entryValue)
|
||||
|
||||
var obj
|
||||
switch (valueType(currentValue)) {
|
||||
case 'undefined':
|
||||
if (step.nextType === 'array') {
|
||||
context[step.key] = []
|
||||
} else {
|
||||
context[step.key] = Object.create(null)
|
||||
}
|
||||
return context[step.key]
|
||||
case 'object':
|
||||
return context[step.key]
|
||||
case 'array':
|
||||
if (step.nextType === 'array') {
|
||||
return currentValue
|
||||
}
|
||||
|
||||
obj = Object.create(null)
|
||||
context[step.key] = obj
|
||||
currentValue.forEach(function (item, i) {
|
||||
if (item !== undefined) obj['' + i] = item
|
||||
})
|
||||
|
||||
return obj
|
||||
case 'scalar':
|
||||
obj = Object.create(null)
|
||||
obj[''] = currentValue
|
||||
context[step.key] = obj
|
||||
return obj
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = setValue
|
52
express-server/node_modules/append-field/package.json
generated
vendored
Normal file
52
express-server/node_modules/append-field/package.json
generated
vendored
Normal file
@ -0,0 +1,52 @@
|
||||
{
|
||||
"_from": "append-field@^1.0.0",
|
||||
"_id": "append-field@1.0.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-HjRA6RXwsSA9I3SOeO3XubW0PlY=",
|
||||
"_location": "/append-field",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "append-field@^1.0.0",
|
||||
"name": "append-field",
|
||||
"escapedName": "append-field",
|
||||
"rawSpec": "^1.0.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^1.0.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/multer"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/append-field/-/append-field-1.0.0.tgz",
|
||||
"_shasum": "1e3440e915f0b1203d23748e78edd7b9b5b43e56",
|
||||
"_spec": "append-field@^1.0.0",
|
||||
"_where": "D:\\5CHITM\\Diplomarbeit\\repos\\SmartShopper\\express-server\\node_modules\\multer",
|
||||
"author": {
|
||||
"name": "Linus Unnebäck",
|
||||
"email": "linus@folkdatorn.se"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/LinusU/node-append-field/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"deprecated": false,
|
||||
"description": "A [W3C HTML JSON forms spec](http://www.w3.org/TR/html-json-forms/) compliant field appender (for lack of a better name). Useful for people implementing `application/x-www-form-urlencoded` and `multipart/form-data` parsers.",
|
||||
"devDependencies": {
|
||||
"mocha": "^2.2.4",
|
||||
"standard": "^6.0.5",
|
||||
"testdata-w3c-json-form": "^0.2.0"
|
||||
},
|
||||
"homepage": "https://github.com/LinusU/node-append-field#readme",
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"name": "append-field",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+ssh://git@github.com/LinusU/node-append-field.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "standard && mocha"
|
||||
},
|
||||
"version": "1.0.0"
|
||||
}
|
19
express-server/node_modules/append-field/test/forms.js
generated
vendored
Normal file
19
express-server/node_modules/append-field/test/forms.js
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
/* eslint-env mocha */
|
||||
|
||||
var assert = require('assert')
|
||||
var appendField = require('../')
|
||||
var testData = require('testdata-w3c-json-form')
|
||||
|
||||
describe('Append Field', function () {
|
||||
for (var test of testData) {
|
||||
it('handles ' + test.name, function () {
|
||||
var store = Object.create(null)
|
||||
|
||||
for (var field of test.fields) {
|
||||
appendField(store, field.key, field.value)
|
||||
}
|
||||
|
||||
assert.deepEqual(store, test.expected)
|
||||
})
|
||||
}
|
||||
})
|
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);
|
||||
});
|
27
express-server/node_modules/charenc/LICENSE.mkd
generated
vendored
Normal file
27
express-server/node_modules/charenc/LICENSE.mkd
generated
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
Copyright © 2011, Paul Vorbach. All rights reserved.
|
||||
Copyright © 2009, Jeff Mott. All rights reserved.
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
* Neither the name Crypto-JS nor the names of its contributors may be used to
|
||||
endorse or promote products derived from this software without specific prior
|
||||
written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
1
express-server/node_modules/charenc/README.js
generated
vendored
Normal file
1
express-server/node_modules/charenc/README.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
**enc** provides crypto character encoding utilities.
|
33
express-server/node_modules/charenc/charenc.js
generated
vendored
Normal file
33
express-server/node_modules/charenc/charenc.js
generated
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
var charenc = {
|
||||
// UTF-8 encoding
|
||||
utf8: {
|
||||
// Convert a string to a byte array
|
||||
stringToBytes: function(str) {
|
||||
return charenc.bin.stringToBytes(unescape(encodeURIComponent(str)));
|
||||
},
|
||||
|
||||
// Convert a byte array to a string
|
||||
bytesToString: function(bytes) {
|
||||
return decodeURIComponent(escape(charenc.bin.bytesToString(bytes)));
|
||||
}
|
||||
},
|
||||
|
||||
// Binary encoding
|
||||
bin: {
|
||||
// Convert a string to a byte array
|
||||
stringToBytes: function(str) {
|
||||
for (var bytes = [], i = 0; i < str.length; i++)
|
||||
bytes.push(str.charCodeAt(i) & 0xFF);
|
||||
return bytes;
|
||||
},
|
||||
|
||||
// Convert a byte array to a string
|
||||
bytesToString: function(bytes) {
|
||||
for (var str = [], i = 0; i < bytes.length; i++)
|
||||
str.push(String.fromCharCode(bytes[i]));
|
||||
return str.join('');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = charenc;
|
54
express-server/node_modules/charenc/package.json
generated
vendored
Normal file
54
express-server/node_modules/charenc/package.json
generated
vendored
Normal file
@ -0,0 +1,54 @@
|
||||
{
|
||||
"_from": "charenc@~0.0.1",
|
||||
"_id": "charenc@0.0.2",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-wKHS86cJLgN3S/qD8UwPxXkKhmc=",
|
||||
"_location": "/charenc",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "charenc@~0.0.1",
|
||||
"name": "charenc",
|
||||
"escapedName": "charenc",
|
||||
"rawSpec": "~0.0.1",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "~0.0.1"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/md5"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/charenc/-/charenc-0.0.2.tgz",
|
||||
"_shasum": "c0a1d2f3a7092e03774bfa83f14c0fc5790a8667",
|
||||
"_spec": "charenc@~0.0.1",
|
||||
"_where": "D:\\5CHITM\\Diplomarbeit\\repos\\SmartShopper\\express-server\\node_modules\\md5",
|
||||
"author": {
|
||||
"name": "Paul Vorbach",
|
||||
"email": "paul@vorb.de",
|
||||
"url": "http://vorb.de"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/pvorb/node-charenc/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"deprecated": false,
|
||||
"description": "character encoding utilities",
|
||||
"engines": {
|
||||
"node": "*"
|
||||
},
|
||||
"homepage": "https://github.com/pvorb/node-charenc#readme",
|
||||
"license": "BSD-3-Clause",
|
||||
"main": "charenc.js",
|
||||
"name": "charenc",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/pvorb/node-charenc.git"
|
||||
},
|
||||
"tags": [
|
||||
"utf8",
|
||||
"binary",
|
||||
"byte",
|
||||
"string"
|
||||
],
|
||||
"version": "0.0.2"
|
||||
}
|
27
express-server/node_modules/crypt/LICENSE.mkd
generated
vendored
Normal file
27
express-server/node_modules/crypt/LICENSE.mkd
generated
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
Copyright © 2011, Paul Vorbach. All rights reserved.
|
||||
Copyright © 2009, Jeff Mott. All rights reserved.
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
* Neither the name Crypto-JS nor the names of its contributors may be used to
|
||||
endorse or promote products derived from this software without specific prior
|
||||
written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
1
express-server/node_modules/crypt/README.mkd
generated
vendored
Normal file
1
express-server/node_modules/crypt/README.mkd
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
**crypt** provides utilities for encryption and hashing
|
96
express-server/node_modules/crypt/crypt.js
generated
vendored
Normal file
96
express-server/node_modules/crypt/crypt.js
generated
vendored
Normal file
@ -0,0 +1,96 @@
|
||||
(function() {
|
||||
var base64map
|
||||
= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',
|
||||
|
||||
crypt = {
|
||||
// Bit-wise rotation left
|
||||
rotl: function(n, b) {
|
||||
return (n << b) | (n >>> (32 - b));
|
||||
},
|
||||
|
||||
// Bit-wise rotation right
|
||||
rotr: function(n, b) {
|
||||
return (n << (32 - b)) | (n >>> b);
|
||||
},
|
||||
|
||||
// Swap big-endian to little-endian and vice versa
|
||||
endian: function(n) {
|
||||
// If number given, swap endian
|
||||
if (n.constructor == Number) {
|
||||
return crypt.rotl(n, 8) & 0x00FF00FF | crypt.rotl(n, 24) & 0xFF00FF00;
|
||||
}
|
||||
|
||||
// Else, assume array and swap all items
|
||||
for (var i = 0; i < n.length; i++)
|
||||
n[i] = crypt.endian(n[i]);
|
||||
return n;
|
||||
},
|
||||
|
||||
// Generate an array of any length of random bytes
|
||||
randomBytes: function(n) {
|
||||
for (var bytes = []; n > 0; n--)
|
||||
bytes.push(Math.floor(Math.random() * 256));
|
||||
return bytes;
|
||||
},
|
||||
|
||||
// Convert a byte array to big-endian 32-bit words
|
||||
bytesToWords: function(bytes) {
|
||||
for (var words = [], i = 0, b = 0; i < bytes.length; i++, b += 8)
|
||||
words[b >>> 5] |= bytes[i] << (24 - b % 32);
|
||||
return words;
|
||||
},
|
||||
|
||||
// Convert big-endian 32-bit words to a byte array
|
||||
wordsToBytes: function(words) {
|
||||
for (var bytes = [], b = 0; b < words.length * 32; b += 8)
|
||||
bytes.push((words[b >>> 5] >>> (24 - b % 32)) & 0xFF);
|
||||
return bytes;
|
||||
},
|
||||
|
||||
// Convert a byte array to a hex string
|
||||
bytesToHex: function(bytes) {
|
||||
for (var hex = [], i = 0; i < bytes.length; i++) {
|
||||
hex.push((bytes[i] >>> 4).toString(16));
|
||||
hex.push((bytes[i] & 0xF).toString(16));
|
||||
}
|
||||
return hex.join('');
|
||||
},
|
||||
|
||||
// Convert a hex string to a byte array
|
||||
hexToBytes: function(hex) {
|
||||
for (var bytes = [], c = 0; c < hex.length; c += 2)
|
||||
bytes.push(parseInt(hex.substr(c, 2), 16));
|
||||
return bytes;
|
||||
},
|
||||
|
||||
// Convert a byte array to a base-64 string
|
||||
bytesToBase64: function(bytes) {
|
||||
for (var base64 = [], i = 0; i < bytes.length; i += 3) {
|
||||
var triplet = (bytes[i] << 16) | (bytes[i + 1] << 8) | bytes[i + 2];
|
||||
for (var j = 0; j < 4; j++)
|
||||
if (i * 8 + j * 6 <= bytes.length * 8)
|
||||
base64.push(base64map.charAt((triplet >>> 6 * (3 - j)) & 0x3F));
|
||||
else
|
||||
base64.push('=');
|
||||
}
|
||||
return base64.join('');
|
||||
},
|
||||
|
||||
// Convert a base-64 string to a byte array
|
||||
base64ToBytes: function(base64) {
|
||||
// Remove non-base-64 characters
|
||||
base64 = base64.replace(/[^A-Z0-9+\/]/ig, '');
|
||||
|
||||
for (var bytes = [], i = 0, imod4 = 0; i < base64.length;
|
||||
imod4 = ++i % 4) {
|
||||
if (imod4 == 0) continue;
|
||||
bytes.push(((base64map.indexOf(base64.charAt(i - 1))
|
||||
& (Math.pow(2, -2 * imod4 + 8) - 1)) << (imod4 * 2))
|
||||
| (base64map.indexOf(base64.charAt(i)) >>> (6 - imod4 * 2)));
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = crypt;
|
||||
})();
|
52
express-server/node_modules/crypt/package.json
generated
vendored
Normal file
52
express-server/node_modules/crypt/package.json
generated
vendored
Normal file
@ -0,0 +1,52 @@
|
||||
{
|
||||
"_from": "crypt@~0.0.1",
|
||||
"_id": "crypt@0.0.2",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-iNf/fsDfuG9xPch7u0LQRNPmxBs=",
|
||||
"_location": "/crypt",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "crypt@~0.0.1",
|
||||
"name": "crypt",
|
||||
"escapedName": "crypt",
|
||||
"rawSpec": "~0.0.1",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "~0.0.1"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/md5"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/crypt/-/crypt-0.0.2.tgz",
|
||||
"_shasum": "88d7ff7ec0dfb86f713dc87bbb42d044d3e6c41b",
|
||||
"_spec": "crypt@~0.0.1",
|
||||
"_where": "D:\\5CHITM\\Diplomarbeit\\repos\\SmartShopper\\express-server\\node_modules\\md5",
|
||||
"author": {
|
||||
"name": "Paul Vorbach",
|
||||
"email": "paul@vorb.de",
|
||||
"url": "http://vorb.de"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/pvorb/node-crypt/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"deprecated": false,
|
||||
"description": "utilities for encryption and hashing",
|
||||
"engines": {
|
||||
"node": "*"
|
||||
},
|
||||
"homepage": "https://github.com/pvorb/node-crypt#readme",
|
||||
"license": "BSD-3-Clause",
|
||||
"main": "crypt.js",
|
||||
"name": "crypt",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/pvorb/node-crypt.git"
|
||||
},
|
||||
"tags": [
|
||||
"hash",
|
||||
"security"
|
||||
],
|
||||
"version": "0.0.2"
|
||||
}
|
16
express-server/node_modules/dicer/.travis.yml
generated
vendored
Normal file
16
express-server/node_modules/dicer/.travis.yml
generated
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
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="5"
|
||||
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/dicer/LICENSE
generated
vendored
Normal file
19
express-server/node_modules/dicer/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.
|
122
express-server/node_modules/dicer/README.md
generated
vendored
Normal file
122
express-server/node_modules/dicer/README.md
generated
vendored
Normal file
@ -0,0 +1,122 @@
|
||||
|
||||
Description
|
||||
===========
|
||||
|
||||
A very fast streaming multipart parser for node.js.
|
||||
|
||||
Benchmarks can be found [here](https://github.com/mscdex/dicer/wiki/Benchmarks).
|
||||
|
||||
|
||||
Requirements
|
||||
============
|
||||
|
||||
* [node.js](http://nodejs.org/) -- v0.8.0 or newer
|
||||
|
||||
|
||||
Install
|
||||
============
|
||||
|
||||
npm install dicer
|
||||
|
||||
|
||||
Examples
|
||||
========
|
||||
|
||||
* Parse an HTTP form upload
|
||||
|
||||
```javascript
|
||||
var inspect = require('util').inspect,
|
||||
http = require('http');
|
||||
|
||||
var Dicer = require('dicer');
|
||||
|
||||
// quick and dirty way to parse multipart boundary
|
||||
var RE_BOUNDARY = /^multipart\/.+?(?:; boundary=(?:(?:"(.+)")|(?:([^\s]+))))$/i,
|
||||
HTML = new Buffer('<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>'),
|
||||
PORT = 8080;
|
||||
|
||||
http.createServer(function(req, res) {
|
||||
var m;
|
||||
if (req.method === 'POST'
|
||||
&& req.headers['content-type']
|
||||
&& (m = RE_BOUNDARY.exec(req.headers['content-type']))) {
|
||||
var d = new Dicer({ boundary: m[1] || m[2] });
|
||||
|
||||
d.on('part', function(p) {
|
||||
console.log('New part!');
|
||||
p.on('header', function(header) {
|
||||
for (var h in header) {
|
||||
console.log('Part header: k: ' + inspect(h)
|
||||
+ ', v: ' + inspect(header[h]));
|
||||
}
|
||||
});
|
||||
p.on('data', function(data) {
|
||||
console.log('Part data: ' + inspect(data.toString()));
|
||||
});
|
||||
p.on('end', function() {
|
||||
console.log('End of part\n');
|
||||
});
|
||||
});
|
||||
d.on('finish', function() {
|
||||
console.log('End of parts');
|
||||
res.writeHead(200);
|
||||
res.end('Form submission successful!');
|
||||
});
|
||||
req.pipe(d);
|
||||
} else if (req.method === 'GET' && req.url === '/') {
|
||||
res.writeHead(200);
|
||||
res.end(HTML);
|
||||
} else {
|
||||
res.writeHead(404);
|
||||
res.end();
|
||||
}
|
||||
}).listen(PORT, function() {
|
||||
console.log('Listening for requests on port ' + PORT);
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
API
|
||||
===
|
||||
|
||||
_Dicer_ is a _WritableStream_
|
||||
|
||||
Dicer (special) events
|
||||
----------------------
|
||||
|
||||
* **finish**() - Emitted when all parts have been parsed and the Dicer instance has been ended.
|
||||
|
||||
* **part**(< _PartStream_ >stream) - Emitted when a new part has been found.
|
||||
|
||||
* **preamble**(< _PartStream_ >stream) - Emitted for preamble if you should happen to need it (can usually be ignored).
|
||||
|
||||
* **trailer**(< _Buffer_ >data) - Emitted when trailing data was found after the terminating boundary (as with the preamble, this can usually be ignored too).
|
||||
|
||||
|
||||
Dicer methods
|
||||
-------------
|
||||
|
||||
* **(constructor)**(< _object_ >config) - Creates and returns a new Dicer instance with the following valid `config` settings:
|
||||
|
||||
* **boundary** - _string_ - This is the boundary used to detect the beginning of a new part.
|
||||
|
||||
* **headerFirst** - _boolean_ - If true, preamble header parsing will be performed first.
|
||||
|
||||
* **maxHeaderPairs** - _integer_ - The maximum number of header key=>value pairs to parse **Default:** 2000 (same as node's http).
|
||||
|
||||
* **setBoundary**(< _string_ >boundary) - _(void)_ - Sets the boundary to use for parsing and performs some initialization needed for parsing. You should only need to use this if you set `headerFirst` to true in the constructor and are parsing the boundary from the preamble header.
|
||||
|
||||
|
||||
|
||||
_PartStream_ is a _ReadableStream_
|
||||
|
||||
PartStream (special) events
|
||||
---------------------------
|
||||
|
||||
* **header**(< _object_ >header) - An object containing the header for this particular part. Each property value is an _array_ of one or more string values.
|
63
express-server/node_modules/dicer/bench/dicer-bench-multipart-parser.js
generated
vendored
Normal file
63
express-server/node_modules/dicer/bench/dicer-bench-multipart-parser.js
generated
vendored
Normal file
@ -0,0 +1,63 @@
|
||||
var assert = require('assert');
|
||||
var Dicer = require('..'),
|
||||
boundary = '-----------------------------168072824752491622650073',
|
||||
d = new Dicer({ boundary: boundary }),
|
||||
mb = 100,
|
||||
buffer = createMultipartBuffer(boundary, mb * 1024 * 1024),
|
||||
callbacks =
|
||||
{ partBegin: -1,
|
||||
partEnd: -1,
|
||||
headerField: -1,
|
||||
headerValue: -1,
|
||||
partData: -1,
|
||||
end: -1,
|
||||
};
|
||||
|
||||
|
||||
d.on('part', function(p) {
|
||||
callbacks.partBegin++;
|
||||
p.on('header', function(header) {
|
||||
/*for (var h in header)
|
||||
console.log('Part header: k: ' + inspect(h) + ', v: ' + inspect(header[h]));*/
|
||||
});
|
||||
p.on('data', function(data) {
|
||||
callbacks.partData++;
|
||||
//console.log('Part data: ' + inspect(data.toString()));
|
||||
});
|
||||
p.on('end', function() {
|
||||
//console.log('End of part\n');
|
||||
callbacks.partEnd++;
|
||||
});
|
||||
});
|
||||
d.on('end', function() {
|
||||
//console.log('End of parts');
|
||||
callbacks.end++;
|
||||
});
|
||||
|
||||
var start = +new Date(),
|
||||
nparsed = d.write(buffer),
|
||||
duration = +new Date - start,
|
||||
mbPerSec = (mb / (duration / 1000)).toFixed(2);
|
||||
|
||||
console.log(mbPerSec+' mb/sec');
|
||||
|
||||
//assert.equal(nparsed, buffer.length);
|
||||
|
||||
function createMultipartBuffer(boundary, size) {
|
||||
var head =
|
||||
'--'+boundary+'\r\n'
|
||||
+ 'content-disposition: form-data; name="field1"\r\n'
|
||||
+ '\r\n'
|
||||
, tail = '\r\n--'+boundary+'--\r\n'
|
||||
, buffer = new Buffer(size);
|
||||
|
||||
buffer.write(head, 'ascii', 0);
|
||||
buffer.write(tail, 'ascii', buffer.length - tail.length);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
process.on('exit', function() {
|
||||
/*for (var k in callbacks) {
|
||||
assert.equal(0, callbacks[k], k+' count off by '+callbacks[k]);
|
||||
}*/
|
||||
});
|
70
express-server/node_modules/dicer/bench/formidable-bench-multipart-parser.js
generated
vendored
Normal file
70
express-server/node_modules/dicer/bench/formidable-bench-multipart-parser.js
generated
vendored
Normal file
@ -0,0 +1,70 @@
|
||||
var assert = require('assert');
|
||||
require('../node_modules/formidable/test/common');
|
||||
var multipartParser = require('../node_modules/formidable/lib/multipart_parser'),
|
||||
MultipartParser = multipartParser.MultipartParser,
|
||||
parser = new MultipartParser(),
|
||||
boundary = '-----------------------------168072824752491622650073',
|
||||
mb = 100,
|
||||
buffer = createMultipartBuffer(boundary, mb * 1024 * 1024),
|
||||
callbacks =
|
||||
{ partBegin: -1,
|
||||
partEnd: -1,
|
||||
headerField: -1,
|
||||
headerValue: -1,
|
||||
partData: -1,
|
||||
end: -1,
|
||||
};
|
||||
|
||||
|
||||
parser.initWithBoundary(boundary);
|
||||
parser.onHeaderField = function() {
|
||||
callbacks.headerField++;
|
||||
};
|
||||
|
||||
parser.onHeaderValue = function() {
|
||||
callbacks.headerValue++;
|
||||
};
|
||||
|
||||
parser.onPartBegin = function() {
|
||||
callbacks.partBegin++;
|
||||
};
|
||||
|
||||
parser.onPartData = function() {
|
||||
callbacks.partData++;
|
||||
};
|
||||
|
||||
parser.onPartEnd = function() {
|
||||
callbacks.partEnd++;
|
||||
};
|
||||
|
||||
parser.onEnd = function() {
|
||||
callbacks.end++;
|
||||
};
|
||||
|
||||
var start = +new Date(),
|
||||
nparsed = parser.write(buffer),
|
||||
duration = +new Date - start,
|
||||
mbPerSec = (mb / (duration / 1000)).toFixed(2);
|
||||
|
||||
console.log(mbPerSec+' mb/sec');
|
||||
|
||||
//assert.equal(nparsed, buffer.length);
|
||||
|
||||
function createMultipartBuffer(boundary, size) {
|
||||
var head =
|
||||
'--'+boundary+'\r\n'
|
||||
+ 'content-disposition: form-data; name="field1"\r\n'
|
||||
+ '\r\n'
|
||||
, tail = '\r\n--'+boundary+'--\r\n'
|
||||
, buffer = new Buffer(size);
|
||||
|
||||
buffer.write(head, 'ascii', 0);
|
||||
buffer.write(tail, 'ascii', buffer.length - tail.length);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
process.on('exit', function() {
|
||||
/*for (var k in callbacks) {
|
||||
assert.equal(0, callbacks[k], k+' count off by '+callbacks[k]);
|
||||
}*/
|
||||
});
|
56
express-server/node_modules/dicer/bench/multipartser-bench-multipart-parser.js
generated
vendored
Normal file
56
express-server/node_modules/dicer/bench/multipartser-bench-multipart-parser.js
generated
vendored
Normal file
@ -0,0 +1,56 @@
|
||||
var assert = require('assert');
|
||||
var multipartser = require('multipartser'),
|
||||
boundary = '-----------------------------168072824752491622650073',
|
||||
parser = multipartser(),
|
||||
mb = 100,
|
||||
buffer = createMultipartBuffer(boundary, mb * 1024 * 1024),
|
||||
callbacks =
|
||||
{ partBegin: -1,
|
||||
partEnd: -1,
|
||||
headerField: -1,
|
||||
headerValue: -1,
|
||||
partData: -1,
|
||||
end: -1,
|
||||
};
|
||||
|
||||
parser.boundary( boundary );
|
||||
|
||||
parser.on( 'part', function ( part ) {
|
||||
});
|
||||
|
||||
parser.on( 'end', function () {
|
||||
//console.log( 'completed parsing' );
|
||||
});
|
||||
|
||||
parser.on( 'error', function ( error ) {
|
||||
console.error( error );
|
||||
});
|
||||
|
||||
var start = +new Date(),
|
||||
nparsed = parser.data(buffer),
|
||||
nend = parser.end(),
|
||||
duration = +new Date - start,
|
||||
mbPerSec = (mb / (duration / 1000)).toFixed(2);
|
||||
|
||||
console.log(mbPerSec+' mb/sec');
|
||||
|
||||
//assert.equal(nparsed, buffer.length);
|
||||
|
||||
function createMultipartBuffer(boundary, size) {
|
||||
var head =
|
||||
'--'+boundary+'\r\n'
|
||||
+ 'content-disposition: form-data; name="field1"\r\n'
|
||||
+ '\r\n'
|
||||
, tail = '\r\n--'+boundary+'--\r\n'
|
||||
, buffer = new Buffer(size);
|
||||
|
||||
buffer.write(head, 'ascii', 0);
|
||||
buffer.write(tail, 'ascii', buffer.length - tail.length);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
process.on('exit', function() {
|
||||
/*for (var k in callbacks) {
|
||||
assert.equal(0, callbacks[k], k+' count off by '+callbacks[k]);
|
||||
}*/
|
||||
});
|
76
express-server/node_modules/dicer/bench/multiparty-bench-multipart-parser.js
generated
vendored
Normal file
76
express-server/node_modules/dicer/bench/multiparty-bench-multipart-parser.js
generated
vendored
Normal file
@ -0,0 +1,76 @@
|
||||
var assert = require('assert'),
|
||||
Form = require('multiparty').Form,
|
||||
boundary = '-----------------------------168072824752491622650073',
|
||||
mb = 100,
|
||||
buffer = createMultipartBuffer(boundary, mb * 1024 * 1024),
|
||||
callbacks =
|
||||
{ partBegin: -1,
|
||||
partEnd: -1,
|
||||
headerField: -1,
|
||||
headerValue: -1,
|
||||
partData: -1,
|
||||
end: -1,
|
||||
};
|
||||
|
||||
var form = new Form({ boundary: boundary });
|
||||
|
||||
hijack('onParseHeaderField', function() {
|
||||
callbacks.headerField++;
|
||||
});
|
||||
|
||||
hijack('onParseHeaderValue', function() {
|
||||
callbacks.headerValue++;
|
||||
});
|
||||
|
||||
hijack('onParsePartBegin', function() {
|
||||
callbacks.partBegin++;
|
||||
});
|
||||
|
||||
hijack('onParsePartData', function() {
|
||||
callbacks.partData++;
|
||||
});
|
||||
|
||||
hijack('onParsePartEnd', function() {
|
||||
callbacks.partEnd++;
|
||||
});
|
||||
|
||||
form.on('finish', function() {
|
||||
callbacks.end++;
|
||||
});
|
||||
|
||||
var start = new Date();
|
||||
form.write(buffer, function(err) {
|
||||
var duration = new Date() - start;
|
||||
assert.ifError(err);
|
||||
var mbPerSec = (mb / (duration / 1000)).toFixed(2);
|
||||
console.log(mbPerSec+' mb/sec');
|
||||
});
|
||||
|
||||
//assert.equal(nparsed, buffer.length);
|
||||
|
||||
function createMultipartBuffer(boundary, size) {
|
||||
var head =
|
||||
'--'+boundary+'\r\n'
|
||||
+ 'content-disposition: form-data; name="field1"\r\n'
|
||||
+ '\r\n'
|
||||
, tail = '\r\n--'+boundary+'--\r\n'
|
||||
, buffer = new Buffer(size);
|
||||
|
||||
buffer.write(head, 'ascii', 0);
|
||||
buffer.write(tail, 'ascii', buffer.length - tail.length);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
process.on('exit', function() {
|
||||
/*for (var k in callbacks) {
|
||||
assert.equal(0, callbacks[k], k+' count off by '+callbacks[k]);
|
||||
}*/
|
||||
});
|
||||
|
||||
function hijack(name, fn) {
|
||||
var oldFn = form[name];
|
||||
form[name] = function() {
|
||||
fn();
|
||||
return oldFn.apply(this, arguments);
|
||||
};
|
||||
}
|
63
express-server/node_modules/dicer/bench/parted-bench-multipart-parser.js
generated
vendored
Normal file
63
express-server/node_modules/dicer/bench/parted-bench-multipart-parser.js
generated
vendored
Normal file
@ -0,0 +1,63 @@
|
||||
// A special, edited version of the multipart parser from parted is needed here
|
||||
// because otherwise it attempts to do some things above and beyond just parsing
|
||||
// -- like saving to disk and whatnot
|
||||
|
||||
var assert = require('assert');
|
||||
var Parser = require('./parted-multipart'),
|
||||
boundary = '-----------------------------168072824752491622650073',
|
||||
parser = new Parser('boundary=' + boundary),
|
||||
mb = 100,
|
||||
buffer = createMultipartBuffer(boundary, mb * 1024 * 1024),
|
||||
callbacks =
|
||||
{ partBegin: -1,
|
||||
partEnd: -1,
|
||||
headerField: -1,
|
||||
headerValue: -1,
|
||||
partData: -1,
|
||||
end: -1,
|
||||
};
|
||||
|
||||
|
||||
parser.on('header', function() {
|
||||
//callbacks.headerField++;
|
||||
});
|
||||
|
||||
parser.on('data', function() {
|
||||
//callbacks.partBegin++;
|
||||
});
|
||||
|
||||
parser.on('part', function() {
|
||||
|
||||
});
|
||||
|
||||
parser.on('end', function() {
|
||||
//callbacks.end++;
|
||||
});
|
||||
|
||||
var start = +new Date(),
|
||||
nparsed = parser.write(buffer),
|
||||
duration = +new Date - start,
|
||||
mbPerSec = (mb / (duration / 1000)).toFixed(2);
|
||||
|
||||
console.log(mbPerSec+' mb/sec');
|
||||
|
||||
//assert.equal(nparsed, buffer.length);
|
||||
|
||||
function createMultipartBuffer(boundary, size) {
|
||||
var head =
|
||||
'--'+boundary+'\r\n'
|
||||
+ 'content-disposition: form-data; name="field1"\r\n'
|
||||
+ '\r\n'
|
||||
, tail = '\r\n--'+boundary+'--\r\n'
|
||||
, buffer = new Buffer(size);
|
||||
|
||||
buffer.write(head, 'ascii', 0);
|
||||
buffer.write(tail, 'ascii', buffer.length - tail.length);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
process.on('exit', function() {
|
||||
/*for (var k in callbacks) {
|
||||
assert.equal(0, callbacks[k], k+' count off by '+callbacks[k]);
|
||||
}*/
|
||||
});
|
485
express-server/node_modules/dicer/bench/parted-multipart.js
generated
vendored
Normal file
485
express-server/node_modules/dicer/bench/parted-multipart.js
generated
vendored
Normal file
@ -0,0 +1,485 @@
|
||||
/**
|
||||
* Parted (https://github.com/chjj/parted)
|
||||
* A streaming multipart state parser.
|
||||
* Copyright (c) 2011, Christopher Jeffrey. (MIT Licensed)
|
||||
*/
|
||||
|
||||
var fs = require('fs')
|
||||
, path = require('path')
|
||||
, EventEmitter = require('events').EventEmitter
|
||||
, StringDecoder = require('string_decoder').StringDecoder
|
||||
, set = require('qs').set
|
||||
, each = Array.prototype.forEach;
|
||||
|
||||
/**
|
||||
* Character Constants
|
||||
*/
|
||||
|
||||
var DASH = '-'.charCodeAt(0)
|
||||
, CR = '\r'.charCodeAt(0)
|
||||
, LF = '\n'.charCodeAt(0)
|
||||
, COLON = ':'.charCodeAt(0)
|
||||
, SPACE = ' '.charCodeAt(0);
|
||||
|
||||
/**
|
||||
* Parser
|
||||
*/
|
||||
|
||||
var Parser = function(type, options) {
|
||||
if (!(this instanceof Parser)) {
|
||||
return new Parser(type, options);
|
||||
}
|
||||
|
||||
EventEmitter.call(this);
|
||||
|
||||
this.writable = true;
|
||||
this.readable = true;
|
||||
|
||||
this.options = options || {};
|
||||
|
||||
var key = grab(type, 'boundary');
|
||||
if (!key) {
|
||||
return this._error('No boundary key found.');
|
||||
}
|
||||
|
||||
this.key = new Buffer('\r\n--' + key);
|
||||
|
||||
this._key = {};
|
||||
each.call(this.key, function(ch) {
|
||||
this._key[ch] = true;
|
||||
}, this);
|
||||
|
||||
this.state = 'start';
|
||||
this.pending = 0;
|
||||
this.written = 0;
|
||||
this.writtenDisk = 0;
|
||||
this.buff = new Buffer(200);
|
||||
|
||||
this.preamble = true;
|
||||
this.epilogue = false;
|
||||
|
||||
this._reset();
|
||||
};
|
||||
|
||||
Parser.prototype.__proto__ = EventEmitter.prototype;
|
||||
|
||||
/**
|
||||
* Parsing
|
||||
*/
|
||||
|
||||
Parser.prototype.write = function(data) {
|
||||
if (!this.writable
|
||||
|| this.epilogue) return;
|
||||
|
||||
try {
|
||||
this._parse(data);
|
||||
} catch (e) {
|
||||
this._error(e);
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
Parser.prototype.end = function(data) {
|
||||
if (!this.writable) return;
|
||||
|
||||
if (data) this.write(data);
|
||||
|
||||
if (!this.epilogue) {
|
||||
return this._error('Message underflow.');
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
Parser.prototype._parse = function(data) {
|
||||
var i = 0
|
||||
, len = data.length
|
||||
, buff = this.buff
|
||||
, key = this.key
|
||||
, ch
|
||||
, val
|
||||
, j;
|
||||
|
||||
for (; i < len; i++) {
|
||||
if (this.pos >= 200) {
|
||||
return this._error('Potential buffer overflow.');
|
||||
}
|
||||
|
||||
ch = data[i];
|
||||
|
||||
switch (this.state) {
|
||||
case 'start':
|
||||
switch (ch) {
|
||||
case DASH:
|
||||
this.pos = 3;
|
||||
this.state = 'key';
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 'key':
|
||||
if (this.pos === key.length) {
|
||||
this.state = 'key_end';
|
||||
i--;
|
||||
} else if (ch !== key[this.pos]) {
|
||||
if (this.preamble) {
|
||||
this.state = 'start';
|
||||
i--;
|
||||
} else {
|
||||
this.state = 'body';
|
||||
val = this.pos - i;
|
||||
if (val > 0) {
|
||||
this._write(key.slice(0, val));
|
||||
}
|
||||
i--;
|
||||
}
|
||||
} else {
|
||||
this.pos++;
|
||||
}
|
||||
break;
|
||||
case 'key_end':
|
||||
switch (ch) {
|
||||
case CR:
|
||||
this.state = 'key_line_end';
|
||||
break;
|
||||
case DASH:
|
||||
this.state = 'key_dash_end';
|
||||
break;
|
||||
default:
|
||||
return this._error('Expected CR or DASH.');
|
||||
}
|
||||
break;
|
||||
case 'key_line_end':
|
||||
switch (ch) {
|
||||
case LF:
|
||||
if (this.preamble) {
|
||||
this.preamble = false;
|
||||
} else {
|
||||
this._finish();
|
||||
}
|
||||
this.state = 'header_name';
|
||||
this.pos = 0;
|
||||
break;
|
||||
default:
|
||||
return this._error('Expected CR.');
|
||||
}
|
||||
break;
|
||||
case 'key_dash_end':
|
||||
switch (ch) {
|
||||
case DASH:
|
||||
this.epilogue = true;
|
||||
this._finish();
|
||||
return;
|
||||
default:
|
||||
return this._error('Expected DASH.');
|
||||
}
|
||||
break;
|
||||
case 'header_name':
|
||||
switch (ch) {
|
||||
case COLON:
|
||||
this.header = buff.toString('ascii', 0, this.pos);
|
||||
this.pos = 0;
|
||||
this.state = 'header_val';
|
||||
break;
|
||||
default:
|
||||
buff[this.pos++] = ch | 32;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 'header_val':
|
||||
switch (ch) {
|
||||
case CR:
|
||||
this.state = 'header_val_end';
|
||||
break;
|
||||
case SPACE:
|
||||
if (this.pos === 0) {
|
||||
break;
|
||||
}
|
||||
; // FALL-THROUGH
|
||||
default:
|
||||
buff[this.pos++] = ch;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 'header_val_end':
|
||||
switch (ch) {
|
||||
case LF:
|
||||
val = buff.toString('ascii', 0, this.pos);
|
||||
this._header(this.header, val);
|
||||
this.pos = 0;
|
||||
this.state = 'header_end';
|
||||
break;
|
||||
default:
|
||||
return this._error('Expected LF.');
|
||||
}
|
||||
break;
|
||||
case 'header_end':
|
||||
switch (ch) {
|
||||
case CR:
|
||||
this.state = 'head_end';
|
||||
break;
|
||||
default:
|
||||
this.state = 'header_name';
|
||||
i--;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 'head_end':
|
||||
switch (ch) {
|
||||
case LF:
|
||||
this.state = 'body';
|
||||
i++;
|
||||
if (i >= len) return;
|
||||
data = data.slice(i);
|
||||
i = -1;
|
||||
len = data.length;
|
||||
break;
|
||||
default:
|
||||
return this._error('Expected LF.');
|
||||
}
|
||||
break;
|
||||
case 'body':
|
||||
switch (ch) {
|
||||
case CR:
|
||||
if (i > 0) {
|
||||
this._write(data.slice(0, i));
|
||||
}
|
||||
this.pos = 1;
|
||||
this.state = 'key';
|
||||
data = data.slice(i);
|
||||
i = 0;
|
||||
len = data.length;
|
||||
break;
|
||||
default:
|
||||
// boyer-moore-like algorithm
|
||||
// at felixge's suggestion
|
||||
while ((j = i + key.length - 1) < len) {
|
||||
if (this._key[data[j]]) break;
|
||||
i = j;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.state === 'body') {
|
||||
this._write(data);
|
||||
}
|
||||
};
|
||||
|
||||
Parser.prototype._header = function(name, val) {
|
||||
/*if (name === 'content-disposition') {
|
||||
this.field = grab(val, 'name');
|
||||
this.file = grab(val, 'filename');
|
||||
|
||||
if (this.file) {
|
||||
this.data = stream(this.file, this.options.path);
|
||||
} else {
|
||||
this.decode = new StringDecoder('utf8');
|
||||
this.data = '';
|
||||
}
|
||||
}*/
|
||||
|
||||
return this.emit('header', name, val);
|
||||
};
|
||||
|
||||
Parser.prototype._write = function(data) {
|
||||
/*if (this.data == null) {
|
||||
return this._error('No disposition.');
|
||||
}
|
||||
|
||||
if (this.file) {
|
||||
this.data.write(data);
|
||||
this.writtenDisk += data.length;
|
||||
} else {
|
||||
this.data += this.decode.write(data);
|
||||
this.written += data.length;
|
||||
}*/
|
||||
|
||||
this.emit('data', data);
|
||||
};
|
||||
|
||||
Parser.prototype._reset = function() {
|
||||
this.pos = 0;
|
||||
this.decode = null;
|
||||
this.field = null;
|
||||
this.data = null;
|
||||
this.file = null;
|
||||
this.header = null;
|
||||
};
|
||||
|
||||
Parser.prototype._error = function(err) {
|
||||
this.destroy();
|
||||
this.emit('error', typeof err === 'string'
|
||||
? new Error(err)
|
||||
: err);
|
||||
};
|
||||
|
||||
Parser.prototype.destroy = function(err) {
|
||||
this.writable = false;
|
||||
this.readable = false;
|
||||
this._reset();
|
||||
};
|
||||
|
||||
Parser.prototype._finish = function() {
|
||||
var self = this
|
||||
, field = this.field
|
||||
, data = this.data
|
||||
, file = this.file
|
||||
, part;
|
||||
|
||||
this.pending++;
|
||||
|
||||
this._reset();
|
||||
|
||||
if (data && data.path) {
|
||||
part = data.path;
|
||||
data.end(next);
|
||||
} else {
|
||||
part = data;
|
||||
next();
|
||||
}
|
||||
|
||||
function next() {
|
||||
if (!self.readable) return;
|
||||
|
||||
self.pending--;
|
||||
|
||||
self.emit('part', field, part);
|
||||
|
||||
if (data && data.path) {
|
||||
self.emit('file', field, part, file);
|
||||
}
|
||||
|
||||
if (self.epilogue && !self.pending) {
|
||||
self.emit('end');
|
||||
self.destroy();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Uploads
|
||||
*/
|
||||
|
||||
Parser.root = process.platform === 'win32'
|
||||
? 'C:/Temp'
|
||||
: '/tmp';
|
||||
|
||||
/**
|
||||
* Middleware
|
||||
*/
|
||||
|
||||
Parser.middleware = function(options) {
|
||||
options = options || {};
|
||||
return function(req, res, next) {
|
||||
if (options.ensureBody) {
|
||||
req.body = {};
|
||||
}
|
||||
|
||||
if (req.method === 'GET'
|
||||
|| req.method === 'HEAD'
|
||||
|| req._multipart) return next();
|
||||
|
||||
req._multipart = true;
|
||||
|
||||
var type = req.headers['content-type'];
|
||||
|
||||
if (type) type = type.split(';')[0].trim().toLowerCase();
|
||||
|
||||
if (type === 'multipart/form-data') {
|
||||
Parser.handle(req, res, next, options);
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Handler
|
||||
*/
|
||||
|
||||
Parser.handle = function(req, res, next, options) {
|
||||
var parser = new Parser(req.headers['content-type'], options)
|
||||
, diskLimit = options.diskLimit
|
||||
, limit = options.limit
|
||||
, parts = {}
|
||||
, files = {};
|
||||
|
||||
parser.on('error', function(err) {
|
||||
req.destroy();
|
||||
next(err);
|
||||
});
|
||||
|
||||
parser.on('part', function(field, part) {
|
||||
set(parts, field, part);
|
||||
});
|
||||
|
||||
parser.on('file', function(field, path, name) {
|
||||
set(files, field, {
|
||||
path: path,
|
||||
name: name,
|
||||
toString: function() {
|
||||
return path;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
parser.on('data', function() {
|
||||
if (this.writtenDisk > diskLimit || this.written > limit) {
|
||||
this.emit('error', new Error('Overflow.'));
|
||||
this.destroy();
|
||||
}
|
||||
});
|
||||
|
||||
parser.on('end', next);
|
||||
|
||||
req.body = parts;
|
||||
req.files = files;
|
||||
req.pipe(parser);
|
||||
};
|
||||
|
||||
/**
|
||||
* Helpers
|
||||
*/
|
||||
|
||||
var isWindows = process.platform === 'win32';
|
||||
|
||||
var stream = function(name, dir) {
|
||||
var ext = path.extname(name) || ''
|
||||
, name = path.basename(name, ext) || ''
|
||||
, dir = dir || Parser.root
|
||||
, tag;
|
||||
|
||||
tag = Math.random().toString(36).substring(2);
|
||||
|
||||
name = name.substring(0, 200) + '.' + tag;
|
||||
name = path.join(dir, name) + ext.substring(0, 6);
|
||||
name = name.replace(/\0/g, '');
|
||||
|
||||
if (isWindows) {
|
||||
name = name.replace(/[:*<>|"?]/g, '');
|
||||
}
|
||||
|
||||
return fs.createWriteStream(name);
|
||||
};
|
||||
|
||||
var grab = function(str, name) {
|
||||
if (!str) return;
|
||||
|
||||
var rx = new RegExp('\\b' + name + '\\s*=\\s*("[^"]+"|\'[^\']+\'|[^;,]+)', 'i')
|
||||
, cap = rx.exec(str);
|
||||
|
||||
if (cap) {
|
||||
return cap[1].trim().replace(/^['"]|['"]$/g, '');
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Expose
|
||||
*/
|
||||
|
||||
module.exports = Parser;
|
240
express-server/node_modules/dicer/lib/Dicer.js
generated
vendored
Normal file
240
express-server/node_modules/dicer/lib/Dicer.js
generated
vendored
Normal file
@ -0,0 +1,240 @@
|
||||
var WritableStream = require('stream').Writable
|
||||
|| require('readable-stream').Writable,
|
||||
inherits = require('util').inherits;
|
||||
|
||||
var StreamSearch = require('streamsearch');
|
||||
|
||||
var PartStream = require('./PartStream'),
|
||||
HeaderParser = require('./HeaderParser');
|
||||
|
||||
var DASH = 45,
|
||||
B_ONEDASH = new Buffer('-'),
|
||||
B_CRLF = new Buffer('\r\n'),
|
||||
EMPTY_FN = function() {};
|
||||
|
||||
function Dicer(cfg) {
|
||||
if (!(this instanceof Dicer))
|
||||
return new Dicer(cfg);
|
||||
WritableStream.call(this, cfg);
|
||||
|
||||
if (!cfg || (!cfg.headerFirst && typeof cfg.boundary !== 'string'))
|
||||
throw new TypeError('Boundary required');
|
||||
|
||||
if (typeof cfg.boundary === 'string')
|
||||
this.setBoundary(cfg.boundary);
|
||||
else
|
||||
this._bparser = undefined;
|
||||
|
||||
this._headerFirst = cfg.headerFirst;
|
||||
|
||||
var self = this;
|
||||
|
||||
this._dashes = 0;
|
||||
this._parts = 0;
|
||||
this._finished = false;
|
||||
this._realFinish = false;
|
||||
this._isPreamble = true;
|
||||
this._justMatched = false;
|
||||
this._firstWrite = true;
|
||||
this._inHeader = true;
|
||||
this._part = undefined;
|
||||
this._cb = undefined;
|
||||
this._ignoreData = false;
|
||||
this._partOpts = (typeof cfg.partHwm === 'number'
|
||||
? { highWaterMark: cfg.partHwm }
|
||||
: {});
|
||||
this._pause = false;
|
||||
|
||||
this._hparser = new HeaderParser(cfg);
|
||||
this._hparser.on('header', function(header) {
|
||||
self._inHeader = false;
|
||||
self._part.emit('header', header);
|
||||
});
|
||||
|
||||
}
|
||||
inherits(Dicer, WritableStream);
|
||||
|
||||
Dicer.prototype.emit = function(ev) {
|
||||
if (ev === 'finish' && !this._realFinish) {
|
||||
if (!this._finished) {
|
||||
var self = this;
|
||||
process.nextTick(function() {
|
||||
self.emit('error', new Error('Unexpected end of multipart data'));
|
||||
if (self._part && !self._ignoreData) {
|
||||
var type = (self._isPreamble ? 'Preamble' : 'Part');
|
||||
self._part.emit('error', new Error(type + ' terminated early due to unexpected end of multipart data'));
|
||||
self._part.push(null);
|
||||
process.nextTick(function() {
|
||||
self._realFinish = true;
|
||||
self.emit('finish');
|
||||
self._realFinish = false;
|
||||
});
|
||||
return;
|
||||
}
|
||||
self._realFinish = true;
|
||||
self.emit('finish');
|
||||
self._realFinish = false;
|
||||
});
|
||||
}
|
||||
} else
|
||||
WritableStream.prototype.emit.apply(this, arguments);
|
||||
};
|
||||
|
||||
Dicer.prototype._write = function(data, encoding, cb) {
|
||||
// ignore unexpected data (e.g. extra trailer data after finished)
|
||||
if (!this._hparser && !this._bparser)
|
||||
return cb();
|
||||
|
||||
if (this._headerFirst && this._isPreamble) {
|
||||
if (!this._part) {
|
||||
this._part = new PartStream(this._partOpts);
|
||||
if (this._events.preamble)
|
||||
this.emit('preamble', this._part);
|
||||
else
|
||||
this._ignore();
|
||||
}
|
||||
var r = this._hparser.push(data);
|
||||
if (!this._inHeader && r !== undefined && r < data.length)
|
||||
data = data.slice(r);
|
||||
else
|
||||
return cb();
|
||||
}
|
||||
|
||||
// allows for "easier" testing
|
||||
if (this._firstWrite) {
|
||||
this._bparser.push(B_CRLF);
|
||||
this._firstWrite = false;
|
||||
}
|
||||
|
||||
this._bparser.push(data);
|
||||
|
||||
if (this._pause)
|
||||
this._cb = cb;
|
||||
else
|
||||
cb();
|
||||
};
|
||||
|
||||
Dicer.prototype.reset = function() {
|
||||
this._part = undefined;
|
||||
this._bparser = undefined;
|
||||
this._hparser = undefined;
|
||||
};
|
||||
|
||||
Dicer.prototype.setBoundary = function(boundary) {
|
||||
var self = this;
|
||||
this._bparser = new StreamSearch('\r\n--' + boundary);
|
||||
this._bparser.on('info', function(isMatch, data, start, end) {
|
||||
self._oninfo(isMatch, data, start, end);
|
||||
});
|
||||
};
|
||||
|
||||
Dicer.prototype._ignore = function() {
|
||||
if (this._part && !this._ignoreData) {
|
||||
this._ignoreData = true;
|
||||
this._part.on('error', EMPTY_FN);
|
||||
// we must perform some kind of read on the stream even though we are
|
||||
// ignoring the data, otherwise node's Readable stream will not emit 'end'
|
||||
// after pushing null to the stream
|
||||
this._part.resume();
|
||||
}
|
||||
};
|
||||
|
||||
Dicer.prototype._oninfo = function(isMatch, data, start, end) {
|
||||
var buf, self = this, i = 0, r, ev, shouldWriteMore = true;
|
||||
|
||||
if (!this._part && this._justMatched && data) {
|
||||
while (this._dashes < 2 && (start + i) < end) {
|
||||
if (data[start + i] === DASH) {
|
||||
++i;
|
||||
++this._dashes;
|
||||
} else {
|
||||
if (this._dashes)
|
||||
buf = B_ONEDASH;
|
||||
this._dashes = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (this._dashes === 2) {
|
||||
if ((start + i) < end && this._events.trailer)
|
||||
this.emit('trailer', data.slice(start + i, end));
|
||||
this.reset();
|
||||
this._finished = true;
|
||||
// no more parts will be added
|
||||
if (self._parts === 0) {
|
||||
self._realFinish = true;
|
||||
self.emit('finish');
|
||||
self._realFinish = false;
|
||||
}
|
||||
}
|
||||
if (this._dashes)
|
||||
return;
|
||||
}
|
||||
if (this._justMatched)
|
||||
this._justMatched = false;
|
||||
if (!this._part) {
|
||||
this._part = new PartStream(this._partOpts);
|
||||
this._part._read = function(n) {
|
||||
self._unpause();
|
||||
};
|
||||
ev = this._isPreamble ? 'preamble' : 'part';
|
||||
if (this._events[ev])
|
||||
this.emit(ev, this._part);
|
||||
else
|
||||
this._ignore();
|
||||
if (!this._isPreamble)
|
||||
this._inHeader = true;
|
||||
}
|
||||
if (data && start < end && !this._ignoreData) {
|
||||
if (this._isPreamble || !this._inHeader) {
|
||||
if (buf)
|
||||
shouldWriteMore = this._part.push(buf);
|
||||
shouldWriteMore = this._part.push(data.slice(start, end));
|
||||
if (!shouldWriteMore)
|
||||
this._pause = true;
|
||||
} else if (!this._isPreamble && this._inHeader) {
|
||||
if (buf)
|
||||
this._hparser.push(buf);
|
||||
r = this._hparser.push(data.slice(start, end));
|
||||
if (!this._inHeader && r !== undefined && r < end)
|
||||
this._oninfo(false, data, start + r, end);
|
||||
}
|
||||
}
|
||||
if (isMatch) {
|
||||
this._hparser.reset();
|
||||
if (this._isPreamble)
|
||||
this._isPreamble = false;
|
||||
else {
|
||||
++this._parts;
|
||||
this._part.on('end', function() {
|
||||
if (--self._parts === 0) {
|
||||
if (self._finished) {
|
||||
self._realFinish = true;
|
||||
self.emit('finish');
|
||||
self._realFinish = false;
|
||||
} else {
|
||||
self._unpause();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
this._part.push(null);
|
||||
this._part = undefined;
|
||||
this._ignoreData = false;
|
||||
this._justMatched = true;
|
||||
this._dashes = 0;
|
||||
}
|
||||
};
|
||||
|
||||
Dicer.prototype._unpause = function() {
|
||||
if (!this._pause)
|
||||
return;
|
||||
|
||||
this._pause = false;
|
||||
if (this._cb) {
|
||||
var cb = this._cb;
|
||||
this._cb = undefined;
|
||||
cb();
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = Dicer;
|
110
express-server/node_modules/dicer/lib/HeaderParser.js
generated
vendored
Normal file
110
express-server/node_modules/dicer/lib/HeaderParser.js
generated
vendored
Normal file
@ -0,0 +1,110 @@
|
||||
var EventEmitter = require('events').EventEmitter,
|
||||
inherits = require('util').inherits;
|
||||
|
||||
var StreamSearch = require('streamsearch');
|
||||
|
||||
var B_DCRLF = new Buffer('\r\n\r\n'),
|
||||
RE_CRLF = /\r\n/g,
|
||||
RE_HDR = /^([^:]+):[ \t]?([\x00-\xFF]+)?$/,
|
||||
MAX_HEADER_PAIRS = 2000, // from node's http.js
|
||||
MAX_HEADER_SIZE = 80 * 1024; // from node's http_parser
|
||||
|
||||
function HeaderParser(cfg) {
|
||||
EventEmitter.call(this);
|
||||
|
||||
var self = this;
|
||||
this.nread = 0;
|
||||
this.maxed = false;
|
||||
this.npairs = 0;
|
||||
this.maxHeaderPairs = (cfg && typeof cfg.maxHeaderPairs === 'number'
|
||||
? cfg.maxHeaderPairs
|
||||
: MAX_HEADER_PAIRS);
|
||||
this.buffer = '';
|
||||
this.header = {};
|
||||
this.finished = false;
|
||||
this.ss = new StreamSearch(B_DCRLF);
|
||||
this.ss.on('info', function(isMatch, data, start, end) {
|
||||
if (data && !self.maxed) {
|
||||
if (self.nread + (end - start) > MAX_HEADER_SIZE) {
|
||||
end = (MAX_HEADER_SIZE - self.nread);
|
||||
self.nread = MAX_HEADER_SIZE;
|
||||
} else
|
||||
self.nread += (end - start);
|
||||
|
||||
if (self.nread === MAX_HEADER_SIZE)
|
||||
self.maxed = true;
|
||||
|
||||
self.buffer += data.toString('binary', start, end);
|
||||
}
|
||||
if (isMatch)
|
||||
self._finish();
|
||||
});
|
||||
}
|
||||
inherits(HeaderParser, EventEmitter);
|
||||
|
||||
HeaderParser.prototype.push = function(data) {
|
||||
var r = this.ss.push(data);
|
||||
if (this.finished)
|
||||
return r;
|
||||
};
|
||||
|
||||
HeaderParser.prototype.reset = function() {
|
||||
this.finished = false;
|
||||
this.buffer = '';
|
||||
this.header = {};
|
||||
this.ss.reset();
|
||||
};
|
||||
|
||||
HeaderParser.prototype._finish = function() {
|
||||
if (this.buffer)
|
||||
this._parseHeader();
|
||||
this.ss.matches = this.ss.maxMatches;
|
||||
var header = this.header;
|
||||
this.header = {};
|
||||
this.buffer = '';
|
||||
this.finished = true;
|
||||
this.nread = this.npairs = 0;
|
||||
this.maxed = false;
|
||||
this.emit('header', header);
|
||||
};
|
||||
|
||||
HeaderParser.prototype._parseHeader = function() {
|
||||
if (this.npairs === this.maxHeaderPairs)
|
||||
return;
|
||||
|
||||
var lines = this.buffer.split(RE_CRLF), len = lines.length, m, h,
|
||||
modded = false;
|
||||
|
||||
for (var i = 0; i < len; ++i) {
|
||||
if (lines[i].length === 0)
|
||||
continue;
|
||||
if (lines[i][0] === '\t' || lines[i][0] === ' ') {
|
||||
// folded header content
|
||||
// RFC2822 says to just remove the CRLF and not the whitespace following
|
||||
// it, so we follow the RFC and include the leading whitespace ...
|
||||
this.header[h][this.header[h].length - 1] += lines[i];
|
||||
} else {
|
||||
m = RE_HDR.exec(lines[i]);
|
||||
if (m) {
|
||||
h = m[1].toLowerCase();
|
||||
if (m[2]) {
|
||||
if (this.header[h] === undefined)
|
||||
this.header[h] = [m[2]];
|
||||
else
|
||||
this.header[h].push(m[2]);
|
||||
} else
|
||||
this.header[h] = [''];
|
||||
if (++this.npairs === this.maxHeaderPairs)
|
||||
break;
|
||||
} else {
|
||||
this.buffer = lines[i];
|
||||
modded = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!modded)
|
||||
this.buffer = '';
|
||||
};
|
||||
|
||||
module.exports = HeaderParser;
|
11
express-server/node_modules/dicer/lib/PartStream.js
generated
vendored
Normal file
11
express-server/node_modules/dicer/lib/PartStream.js
generated
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
var inherits = require('util').inherits,
|
||||
ReadableStream = require('stream').Readable || require('readable-stream');
|
||||
|
||||
function PartStream(opts) {
|
||||
ReadableStream.call(this, opts);
|
||||
}
|
||||
inherits(PartStream, ReadableStream);
|
||||
|
||||
PartStream.prototype._read = function(n) {};
|
||||
|
||||
module.exports = PartStream;
|
5
express-server/node_modules/dicer/node_modules/readable-stream/.npmignore
generated
vendored
Normal file
5
express-server/node_modules/dicer/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/dicer/node_modules/readable-stream/LICENSE
generated
vendored
Normal file
18
express-server/node_modules/dicer/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/dicer/node_modules/readable-stream/README.md
generated
vendored
Normal file
15
express-server/node_modules/dicer/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/dicer/node_modules/readable-stream/duplex.js
generated
vendored
Normal file
1
express-server/node_modules/dicer/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/dicer/node_modules/readable-stream/float.patch
generated
vendored
Normal file
923
express-server/node_modules/dicer/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/dicer/node_modules/readable-stream/lib/_stream_duplex.js
generated
vendored
Normal file
89
express-server/node_modules/dicer/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/dicer/node_modules/readable-stream/lib/_stream_passthrough.js
generated
vendored
Normal file
46
express-server/node_modules/dicer/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/dicer/node_modules/readable-stream/lib/_stream_readable.js
generated
vendored
Normal file
951
express-server/node_modules/dicer/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/dicer/node_modules/readable-stream/lib/_stream_transform.js
generated
vendored
Normal file
209
express-server/node_modules/dicer/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/dicer/node_modules/readable-stream/lib/_stream_writable.js
generated
vendored
Normal file
477
express-server/node_modules/dicer/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/dicer/node_modules/readable-stream/package.json
generated
vendored
Normal file
65
express-server/node_modules/dicer/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": "/dicer/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": [
|
||||
"/dicer"
|
||||
],
|
||||
"_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\\dicer",
|
||||
"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/dicer/node_modules/readable-stream/passthrough.js
generated
vendored
Normal file
1
express-server/node_modules/dicer/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/dicer/node_modules/readable-stream/readable.js
generated
vendored
Normal file
10
express-server/node_modules/dicer/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/dicer/node_modules/readable-stream/transform.js
generated
vendored
Normal file
1
express-server/node_modules/dicer/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/dicer/node_modules/readable-stream/writable.js
generated
vendored
Normal file
1
express-server/node_modules/dicer/node_modules/readable-stream/writable.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
module.exports = require("./lib/_stream_writable.js")
|
72
express-server/node_modules/dicer/package.json
generated
vendored
Normal file
72
express-server/node_modules/dicer/package.json
generated
vendored
Normal file
@ -0,0 +1,72 @@
|
||||
{
|
||||
"_from": "dicer@0.2.5",
|
||||
"_id": "dicer@0.2.5",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-WZbAhrszIYyBLAkL3cCc0S+stw8=",
|
||||
"_location": "/dicer",
|
||||
"_phantomChildren": {
|
||||
"core-util-is": "1.0.2",
|
||||
"inherits": "2.0.3",
|
||||
"isarray": "0.0.1",
|
||||
"string_decoder": "0.10.31"
|
||||
},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "dicer@0.2.5",
|
||||
"name": "dicer",
|
||||
"escapedName": "dicer",
|
||||
"rawSpec": "0.2.5",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "0.2.5"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/busboy"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/dicer/-/dicer-0.2.5.tgz",
|
||||
"_shasum": "5996c086bb33218c812c090bddc09cd12facb70f",
|
||||
"_spec": "dicer@0.2.5",
|
||||
"_where": "D:\\5CHITM\\Diplomarbeit\\repos\\SmartShopper\\express-server\\node_modules\\busboy",
|
||||
"author": {
|
||||
"name": "Brian White",
|
||||
"email": "mscdex@mscdex.net"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/mscdex/dicer/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"readable-stream": "1.1.x",
|
||||
"streamsearch": "0.1.2"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "A very fast streaming multipart parser for node.js",
|
||||
"engines": {
|
||||
"node": ">=0.8.0"
|
||||
},
|
||||
"homepage": "https://github.com/mscdex/dicer#readme",
|
||||
"keywords": [
|
||||
"parser",
|
||||
"parse",
|
||||
"parsing",
|
||||
"multipart",
|
||||
"form-data",
|
||||
"streaming"
|
||||
],
|
||||
"licenses": [
|
||||
{
|
||||
"type": "MIT",
|
||||
"url": "http://github.com/mscdex/dicer/raw/master/LICENSE"
|
||||
}
|
||||
],
|
||||
"main": "./lib/Dicer",
|
||||
"name": "dicer",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+ssh://git@github.com/mscdex/dicer.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "node test/test.js"
|
||||
},
|
||||
"version": "0.2.5"
|
||||
}
|
31
express-server/node_modules/dicer/test/fixtures/many-noend/original
generated
vendored
Normal file
31
express-server/node_modules/dicer/test/fixtures/many-noend/original
generated
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
------WebKitFormBoundaryWLHCs9qmcJJoyjKR
|
||||
Content-Disposition: form-data; name="_method"
|
||||
|
||||
put
|
||||
------WebKitFormBoundaryWLHCs9qmcJJoyjKR
|
||||
Content-Disposition: form-data; name="profile[blog]"
|
||||
|
||||
|
||||
------WebKitFormBoundaryWLHCs9qmcJJoyjKR
|
||||
Content-Disposition: form-data; name="profile[public_email]"
|
||||
|
||||
|
||||
------WebKitFormBoundaryWLHCs9qmcJJoyjKR
|
||||
Content-Disposition: form-data; name="profile[interests]"
|
||||
|
||||
|
||||
------WebKitFormBoundaryWLHCs9qmcJJoyjKR
|
||||
Content-Disposition: form-data; name="profile[bio]"
|
||||
|
||||
hello
|
||||
|
||||
"quote"
|
||||
------WebKitFormBoundaryWLHCs9qmcJJoyjKR
|
||||
Content-Disposition: form-data; name="commit"
|
||||
|
||||
Save
|
||||
------WebKitFormBoundaryWLHCs9qmcJJoyjKR
|
||||
Content-Disposition: form-data; name="media"; filename=""
|
||||
Content-Type: application/octet-stream
|
||||
|
||||
|
1
express-server/node_modules/dicer/test/fixtures/many-noend/part1
generated
vendored
Normal file
1
express-server/node_modules/dicer/test/fixtures/many-noend/part1
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
put
|
1
express-server/node_modules/dicer/test/fixtures/many-noend/part1.header
generated
vendored
Normal file
1
express-server/node_modules/dicer/test/fixtures/many-noend/part1.header
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"content-disposition": ["form-data; name=\"_method\""]}
|
0
express-server/node_modules/dicer/test/fixtures/many-noend/part2
generated
vendored
Normal file
0
express-server/node_modules/dicer/test/fixtures/many-noend/part2
generated
vendored
Normal file
1
express-server/node_modules/dicer/test/fixtures/many-noend/part2.header
generated
vendored
Normal file
1
express-server/node_modules/dicer/test/fixtures/many-noend/part2.header
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"content-disposition": ["form-data; name=\"profile[blog]\""]}
|
0
express-server/node_modules/dicer/test/fixtures/many-noend/part3
generated
vendored
Normal file
0
express-server/node_modules/dicer/test/fixtures/many-noend/part3
generated
vendored
Normal file
1
express-server/node_modules/dicer/test/fixtures/many-noend/part3.header
generated
vendored
Normal file
1
express-server/node_modules/dicer/test/fixtures/many-noend/part3.header
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"content-disposition": ["form-data; name=\"profile[public_email]\""]}
|
0
express-server/node_modules/dicer/test/fixtures/many-noend/part4
generated
vendored
Normal file
0
express-server/node_modules/dicer/test/fixtures/many-noend/part4
generated
vendored
Normal file
1
express-server/node_modules/dicer/test/fixtures/many-noend/part4.header
generated
vendored
Normal file
1
express-server/node_modules/dicer/test/fixtures/many-noend/part4.header
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"content-disposition": ["form-data; name=\"profile[interests]\""]}
|
3
express-server/node_modules/dicer/test/fixtures/many-noend/part5
generated
vendored
Normal file
3
express-server/node_modules/dicer/test/fixtures/many-noend/part5
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
hello
|
||||
|
||||
"quote"
|
1
express-server/node_modules/dicer/test/fixtures/many-noend/part5.header
generated
vendored
Normal file
1
express-server/node_modules/dicer/test/fixtures/many-noend/part5.header
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"content-disposition": ["form-data; name=\"profile[bio]\""]}
|
1
express-server/node_modules/dicer/test/fixtures/many-noend/part6
generated
vendored
Normal file
1
express-server/node_modules/dicer/test/fixtures/many-noend/part6
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
Save
|
1
express-server/node_modules/dicer/test/fixtures/many-noend/part6.header
generated
vendored
Normal file
1
express-server/node_modules/dicer/test/fixtures/many-noend/part6.header
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"content-disposition": ["form-data; name=\"commit\""]}
|
2
express-server/node_modules/dicer/test/fixtures/many-noend/part7.header
generated
vendored
Normal file
2
express-server/node_modules/dicer/test/fixtures/many-noend/part7.header
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
{"content-disposition": ["form-data; name=\"media\"; filename=\"\""],
|
||||
"content-type": ["application/octet-stream"]}
|
32
express-server/node_modules/dicer/test/fixtures/many-wrongboundary/original
generated
vendored
Normal file
32
express-server/node_modules/dicer/test/fixtures/many-wrongboundary/original
generated
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
------WebKitFormBoundaryWLHCs9qmcJJoyjKR
|
||||
Content-Disposition: form-data; name="_method"
|
||||
|
||||
put
|
||||
------WebKitFormBoundaryWLHCs9qmcJJoyjKR
|
||||
Content-Disposition: form-data; name="profile[blog]"
|
||||
|
||||
|
||||
------WebKitFormBoundaryWLHCs9qmcJJoyjKR
|
||||
Content-Disposition: form-data; name="profile[public_email]"
|
||||
|
||||
|
||||
------WebKitFormBoundaryWLHCs9qmcJJoyjKR
|
||||
Content-Disposition: form-data; name="profile[interests]"
|
||||
|
||||
|
||||
------WebKitFormBoundaryWLHCs9qmcJJoyjKR
|
||||
Content-Disposition: form-data; name="profile[bio]"
|
||||
|
||||
hello
|
||||
|
||||
"quote"
|
||||
------WebKitFormBoundaryWLHCs9qmcJJoyjKR
|
||||
Content-Disposition: form-data; name="media"; filename=""
|
||||
Content-Type: application/octet-stream
|
||||
|
||||
|
||||
------WebKitFormBoundaryWLHCs9qmcJJoyjKR
|
||||
Content-Disposition: form-data; name="commit"
|
||||
|
||||
Save
|
||||
------WebKitFormBoundaryWLHCs9qmcJJoyjKR--
|
33
express-server/node_modules/dicer/test/fixtures/many-wrongboundary/preamble
generated
vendored
Normal file
33
express-server/node_modules/dicer/test/fixtures/many-wrongboundary/preamble
generated
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
|
||||
------WebKitFormBoundaryWLHCs9qmcJJoyjKR
|
||||
Content-Disposition: form-data; name="_method"
|
||||
|
||||
put
|
||||
------WebKitFormBoundaryWLHCs9qmcJJoyjKR
|
||||
Content-Disposition: form-data; name="profile[blog]"
|
||||
|
||||
|
||||
------WebKitFormBoundaryWLHCs9qmcJJoyjKR
|
||||
Content-Disposition: form-data; name="profile[public_email]"
|
||||
|
||||
|
||||
------WebKitFormBoundaryWLHCs9qmcJJoyjKR
|
||||
Content-Disposition: form-data; name="profile[interests]"
|
||||
|
||||
|
||||
------WebKitFormBoundaryWLHCs9qmcJJoyjKR
|
||||
Content-Disposition: form-data; name="profile[bio]"
|
||||
|
||||
hello
|
||||
|
||||
"quote"
|
||||
------WebKitFormBoundaryWLHCs9qmcJJoyjKR
|
||||
Content-Disposition: form-data; name="media"; filename=""
|
||||
Content-Type: application/octet-stream
|
||||
|
||||
|
||||
------WebKitFormBoundaryWLHCs9qmcJJoyjKR
|
||||
Content-Disposition: form-data; name="commit"
|
||||
|
||||
Save
|
||||
------WebKitFormBoundaryWLHCs9qmcJJoyjKR--
|
1
express-server/node_modules/dicer/test/fixtures/many-wrongboundary/preamble.error
generated
vendored
Normal file
1
express-server/node_modules/dicer/test/fixtures/many-wrongboundary/preamble.error
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
Preamble terminated early due to unexpected end of multipart data
|
32
express-server/node_modules/dicer/test/fixtures/many/original
generated
vendored
Normal file
32
express-server/node_modules/dicer/test/fixtures/many/original
generated
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
------WebKitFormBoundaryWLHCs9qmcJJoyjKR
|
||||
Content-Disposition: form-data; name="_method"
|
||||
|
||||
put
|
||||
------WebKitFormBoundaryWLHCs9qmcJJoyjKR
|
||||
Content-Disposition: form-data; name="profile[blog]"
|
||||
|
||||
|
||||
------WebKitFormBoundaryWLHCs9qmcJJoyjKR
|
||||
Content-Disposition: form-data; name="profile[public_email]"
|
||||
|
||||
|
||||
------WebKitFormBoundaryWLHCs9qmcJJoyjKR
|
||||
Content-Disposition: form-data; name="profile[interests]"
|
||||
|
||||
|
||||
------WebKitFormBoundaryWLHCs9qmcJJoyjKR
|
||||
Content-Disposition: form-data; name="profile[bio]"
|
||||
|
||||
hello
|
||||
|
||||
"quote"
|
||||
------WebKitFormBoundaryWLHCs9qmcJJoyjKR
|
||||
Content-Disposition: form-data; name="media"; filename=""
|
||||
Content-Type: application/octet-stream
|
||||
|
||||
|
||||
------WebKitFormBoundaryWLHCs9qmcJJoyjKR
|
||||
Content-Disposition: form-data; name="commit"
|
||||
|
||||
Save
|
||||
------WebKitFormBoundaryWLHCs9qmcJJoyjKR--
|
1
express-server/node_modules/dicer/test/fixtures/many/part1
generated
vendored
Normal file
1
express-server/node_modules/dicer/test/fixtures/many/part1
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
put
|
1
express-server/node_modules/dicer/test/fixtures/many/part1.header
generated
vendored
Normal file
1
express-server/node_modules/dicer/test/fixtures/many/part1.header
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"content-disposition": ["form-data; name=\"_method\""]}
|
0
express-server/node_modules/dicer/test/fixtures/many/part2
generated
vendored
Normal file
0
express-server/node_modules/dicer/test/fixtures/many/part2
generated
vendored
Normal file
1
express-server/node_modules/dicer/test/fixtures/many/part2.header
generated
vendored
Normal file
1
express-server/node_modules/dicer/test/fixtures/many/part2.header
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"content-disposition": ["form-data; name=\"profile[blog]\""]}
|
0
express-server/node_modules/dicer/test/fixtures/many/part3
generated
vendored
Normal file
0
express-server/node_modules/dicer/test/fixtures/many/part3
generated
vendored
Normal file
1
express-server/node_modules/dicer/test/fixtures/many/part3.header
generated
vendored
Normal file
1
express-server/node_modules/dicer/test/fixtures/many/part3.header
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"content-disposition": ["form-data; name=\"profile[public_email]\""]}
|
0
express-server/node_modules/dicer/test/fixtures/many/part4
generated
vendored
Normal file
0
express-server/node_modules/dicer/test/fixtures/many/part4
generated
vendored
Normal file
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user