Comparing version 1.0.1 to 2.0.0
@@ -9,3 +9,3 @@ var CombinedStream = require('combined-stream'); | ||
var mime = require('mime-types'); | ||
var async = require('async'); | ||
var asynckit = require('asynckit'); | ||
var populate = require('./populate.js'); | ||
@@ -28,3 +28,3 @@ | ||
if (!(this instanceof FormData)) { | ||
throw new TypeError('Failed to construct FormData: Please use the _new_ operator, this object constructor cannot be called as a function.'); | ||
return new FormData(); | ||
} | ||
@@ -34,3 +34,3 @@ | ||
this._valueLength = 0; | ||
this._lengthRetrievers = []; | ||
this._valuesToMeasure = []; | ||
@@ -107,56 +107,58 @@ CombinedStream.call(this); | ||
if (!options.knownLength) { | ||
this._lengthRetrievers.push(function(next) { | ||
this._valuesToMeasure.push(value); | ||
} | ||
}; | ||
if (value.hasOwnProperty('fd')) { | ||
FormData.prototype._lengthRetriever = function(value, callback) { | ||
// take read range into a account | ||
// `end` = Infinity –> read file till the end | ||
// | ||
// TODO: Looks like there is bug in Node fs.createReadStream | ||
// it doesn't respect `end` options without `start` options | ||
// Fix it when node fixes it. | ||
// https://github.com/joyent/node/issues/7819 | ||
if (value.end != undefined && value.end != Infinity && value.start != undefined) { | ||
if (value.hasOwnProperty('fd')) { | ||
// when end specified | ||
// no need to calculate range | ||
// inclusive, starts with 0 | ||
next(null, value.end + 1 - (value.start ? value.start : 0)); | ||
// take read range into a account | ||
// `end` = Infinity –> read file till the end | ||
// | ||
// TODO: Looks like there is bug in Node fs.createReadStream | ||
// it doesn't respect `end` options without `start` options | ||
// Fix it when node fixes it. | ||
// https://github.com/joyent/node/issues/7819 | ||
if (value.end != undefined && value.end != Infinity && value.start != undefined) { | ||
// not that fast snoopy | ||
} else { | ||
// still need to fetch file size from fs | ||
fs.stat(value.path, function(err, stat) { | ||
// when end specified | ||
// no need to calculate range | ||
// inclusive, starts with 0 | ||
callback(null, value.end + 1 - (value.start ? value.start : 0)); | ||
var fileSize; | ||
// not that fast snoopy | ||
} else { | ||
// still need to fetch file size from fs | ||
fs.stat(value.path, function(err, stat) { | ||
if (err) { | ||
next(err); | ||
return; | ||
} | ||
var fileSize; | ||
// update final size based on the range options | ||
fileSize = stat.size - (value.start ? value.start : 0); | ||
next(null, fileSize); | ||
}); | ||
if (err) { | ||
callback(err); | ||
return; | ||
} | ||
// or http response | ||
} else if (value.hasOwnProperty('httpVersion')) { | ||
next(null, +value.headers['content-length']); | ||
// update final size based on the range options | ||
fileSize = stat.size - (value.start ? value.start : 0); | ||
callback(null, fileSize); | ||
}); | ||
} | ||
// or request stream http://github.com/mikeal/request | ||
} else if (value.hasOwnProperty('httpModule')) { | ||
// wait till response come back | ||
value.on('response', function(response) { | ||
value.pause(); | ||
next(null, +response.headers['content-length']); | ||
}); | ||
value.resume(); | ||
// or http response | ||
} else if (value.hasOwnProperty('httpVersion')) { | ||
callback(null, +value.headers['content-length']); | ||
// something else | ||
} else { | ||
next('Unknown stream'); | ||
} | ||
// or request stream http://github.com/mikeal/request | ||
} else if (value.hasOwnProperty('httpModule')) { | ||
// wait till response come back | ||
value.on('response', function(response) { | ||
value.pause(); | ||
callback(null, +response.headers['content-length']); | ||
}); | ||
value.resume(); | ||
// something else | ||
} else { | ||
callback('Unknown stream'); | ||
} | ||
@@ -298,14 +300,2 @@ }; | ||
// TODO: Looks like unused function | ||
FormData.prototype.getCustomHeaders = function(contentType) { | ||
contentType = contentType ? contentType : 'multipart/form-data'; | ||
var formHeaders = { | ||
'content-type': contentType + '; boundary=' + this.getBoundary(), | ||
'content-length': this.getLengthSync() | ||
}; | ||
return formHeaders; | ||
}; | ||
FormData.prototype.getBoundary = function() { | ||
@@ -343,3 +333,3 @@ if (!this._boundary) { | ||
// https://github.com/form-data/form-data/issues/40 | ||
if (this._lengthRetrievers.length) { | ||
if (this._valuesToMeasure.length) { | ||
// Some async length retrievers are present | ||
@@ -361,3 +351,3 @@ // therefore synchronous length calculation is false. | ||
if (!this._lengthRetrievers.length) { | ||
if (!this._valuesToMeasure.length) { | ||
process.nextTick(cb.bind(this, null, knownLength)); | ||
@@ -367,3 +357,3 @@ return; | ||
async.parallel(this._lengthRetrievers, function(err, values) { | ||
asynckit.parallel(this._valuesToMeasure, this._lengthRetriever, function(err, values) { | ||
if (err) { | ||
@@ -370,0 +360,0 @@ cb(err); |
@@ -5,3 +5,3 @@ { | ||
"description": "A library to create readable \"multipart/form-data\" streams. Can be used to submit forms and file uploads to other web applications.", | ||
"version": "1.0.1", | ||
"version": "2.0.0", | ||
"repository": { | ||
@@ -17,3 +17,4 @@ "type": "git", | ||
"posttest": "istanbul report lcov text", | ||
"lint": "eslint lib/*.js test/*.js test/**/*.js", | ||
"lint": "eslint lib/*.js test/*.js test/integration/*.js", | ||
"ci-lint": "is-node-modern && npm run lint || is-node-not-modern", | ||
"predebug": "rimraf coverage test/tmp", | ||
@@ -35,6 +36,6 @@ "debug": "verbose=1 ./test/run.js", | ||
"engines": { | ||
"node": ">= 0.10" | ||
"node": ">= 0.12" | ||
}, | ||
"dependencies": { | ||
"async": "^2.0.1", | ||
"asynckit": "^0.4.0", | ||
"combined-stream": "^1.0.5", | ||
@@ -44,5 +45,5 @@ "mime-types": "^2.1.11" | ||
"devDependencies": { | ||
"coveralls": "^2.11.12", | ||
"coveralls": "^2.11.13", | ||
"cross-spawn": "^4.0.0", | ||
"eslint": "^2.13.1", | ||
"eslint": "^3.5.0", | ||
"fake": "^0.2.2", | ||
@@ -52,2 +53,3 @@ "far": "^0.0.7", | ||
"in-publish": "^2.0.0", | ||
"is-node-modern": "^1.0.0", | ||
"istanbul": "^0.4.5", | ||
@@ -54,0 +56,0 @@ "pkgfiles": "^2.3.0", |
@@ -8,8 +8,8 @@ # Form-Data [![NPM Module](https://img.shields.io/npm/v/form-data.svg)](https://www.npmjs.com/package/form-data) [![Join the chat at https://gitter.im/form-data/form-data](http://form-data.github.io/images/gitterbadge.svg)](https://gitter.im/form-data/form-data) | ||
[xhr2-fd]: http://dev.w3.org/2006/webapi/XMLHttpRequest-2/Overview.html#the-formdata-interface | ||
[streams2-thing]: http://nodejs.org/api/stream.html#stream_compatibility_with_older_node_versions | ||
[![Linux Build](https://img.shields.io/travis/form-data/form-data/v1.0.1.svg?label=linux:0.10-6.x)](https://travis-ci.org/form-data/form-data) | ||
[![Windows Build](https://img.shields.io/appveyor/ci/alexindigo/form-data/v1.0.1.svg?label=windows:0.10-6.x)](https://ci.appveyor.com/project/alexindigo/form-data) | ||
[![Coverage Status](https://img.shields.io/coveralls/form-data/form-data/v1.0.1.svg?label=code+coverage)](https://coveralls.io/github/form-data/form-data?branch=master) | ||
[![Linux Build](https://img.shields.io/travis/form-data/form-data/v2.0.0.svg?label=linux:0.12-6.x)](https://travis-ci.org/form-data/form-data) | ||
[![MacOS Build](https://img.shields.io/travis/form-data/form-data/v2.0.0.svg?label=macos:0.12-6.x)](https://travis-ci.org/form-data/form-data) | ||
[![Windows Build](https://img.shields.io/appveyor/ci/alexindigo/form-data/v2.0.0.svg?label=windows:0.12-6.x)](https://ci.appveyor.com/project/alexindigo/form-data) | ||
[![Coverage Status](https://img.shields.io/coveralls/form-data/form-data/v2.0.0.svg?label=code+coverage)](https://coveralls.io/github/form-data/form-data?branch=master) | ||
[![Dependency Status](https://img.shields.io/david/form-data/form-data.svg)](https://david-dm.org/form-data/form-data) | ||
@@ -214,3 +214,3 @@ [![bitHound Overall Score](https://www.bithound.io/github/form-data/form-data/badges/score.svg)](https://www.bithound.io/github/form-data/form-data) | ||
- ```getLengthSync()``` method DOESN'T calculate length for streams, use ```knownLength``` options as workaround. | ||
- If it feels like FormData hangs after submit, please check [Compatibility with Older Node Versions][streams2-thing] | ||
- Starting version `2.x` FormData has dropped support for `node@0.10.x`. | ||
@@ -217,0 +217,0 @@ ## License |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3
20912
13
349
+ Addedasynckit@^0.4.0
+ Addedasynckit@0.4.0(transitive)
- Removedasync@^2.0.1
- Removedasync@2.6.4(transitive)
- Removedlodash@4.17.21(transitive)