form-data
Advanced tools
Comparing version 0.0.10 to 0.1.0
@@ -31,2 +31,10 @@ var CombinedStream = require('combined-stream'); | ||
// https://github.com/felixge/node-form-data/issues/38 | ||
if (util.isArray(value)) { | ||
// Please convert your array into string | ||
// the way web server expects it | ||
this._error(new Error('Arrays are not supported.')); | ||
return; | ||
} | ||
var header = this._multiPartHeader(field, value, options); | ||
@@ -46,3 +54,3 @@ var footer = this._multiPartFooter(field, value, options); | ||
// used w/ trackLengthSync(), when length is known. | ||
// used w/ getLengthSync(), when length is known. | ||
// e.g. for streaming directly from a remote server, | ||
@@ -71,11 +79,7 @@ // w/ a known file a size, and not wanting to wait for | ||
// no need to bother with the length | ||
if (!options.knownLength) | ||
this._lengthRetrievers.push(function(next) { | ||
// do we already know the size? | ||
// 0 additional leaves value from getSyncLength() | ||
if (options.knownLength != null) { | ||
next(null, 0); | ||
// check if it's local file | ||
} else if (value.hasOwnProperty('fd')) { | ||
if (value.hasOwnProperty('fd')) { | ||
fs.stat(value.path, function(err, stat) { | ||
@@ -203,10 +207,23 @@ if (err) { | ||
FormData.prototype.getLengthSync = function() { | ||
var knownLength = this._overheadLength + this._valueLength; | ||
// Note: getLengthSync DOESN'T calculate streams length | ||
// As workaround one can calculate file size manually | ||
// and add it as knownLength option | ||
FormData.prototype.getLengthSync = function(debug) { | ||
var knownLength = this._overheadLength + this._valueLength; | ||
if (this._streams.length) { | ||
knownLength += this._lastBoundary().length; | ||
} | ||
// Don't get confused, there are 3 "internal" streams for each keyval pair | ||
// so it basically checks if there is any value added to the form | ||
if (this._streams.length) { | ||
knownLength += this._lastBoundary().length; | ||
} | ||
return knownLength; | ||
// https://github.com/felixge/node-form-data/issues/40 | ||
if (this._lengthRetrievers.length) { | ||
// Some async length retrivers are present | ||
// therefore synchronous length calculation is false. | ||
// Please use getLength(callback) to get proper length | ||
this._error(new Error('Cannot calculate proper length in synchronous way.')); | ||
} | ||
return knownLength; | ||
}; | ||
@@ -286,2 +303,10 @@ | ||
FormData.prototype._error = function(err) { | ||
if (this.error) return; | ||
this.error = err; | ||
this.pause(); | ||
this.emit('error', err); | ||
}; | ||
/* | ||
@@ -288,0 +313,0 @@ * Santa's little helpers |
{ | ||
"author": "Felix Geisendörfer <felix@debuggable.com> (http://debuggable.com/)", | ||
"name": "form-data", | ||
"description": "A module to create readable `\"multipart/form-data\"` streams. Can be used to submit forms and file uploads to other web applications.", | ||
"version": "0.0.10", | ||
"description": "A module to create readable \"multipart/form-data\" streams. Can be used to submit forms and file uploads to other web applications.", | ||
"version": "0.1.0", | ||
"repository": { | ||
@@ -19,11 +19,11 @@ "type": "git", | ||
"combined-stream": "~0.0.4", | ||
"mime": "~1.2.2", | ||
"async": "~0.2.7" | ||
"mime": "~1.2.9", | ||
"async": "~0.2.9" | ||
}, | ||
"devDependencies": { | ||
"fake": "~0.2.1", | ||
"fake": "~0.2.2", | ||
"far": "~0.0.7", | ||
"formidable": "~1.0.13", | ||
"request": "~2.16.6" | ||
"formidable": "~1.0.14", | ||
"request": "~2.22.0" | ||
} | ||
} |
@@ -1,8 +0,6 @@ | ||
# Form-Data [![Build Status](https://travis-ci.org/alexindigo/node-form-data.png?branch=master)](https://travis-ci.org/alexindigo/node-form-data) [![Dependency Status](https://gemnasium.com/alexindigo/node-form-data.png)](https://gemnasium.com/alexindigo/node-form-data) | ||
# Form-Data [![Build Status](https://travis-ci.org/felixge/node-form-data.png?branch=master)](https://travis-ci.org/felixge/node-form-data) [![Dependency Status](https://gemnasium.com/felixge/node-form-data.png)](https://gemnasium.com/felixge/node-form-data) | ||
A module to create readable `"multipart/form-data"` streams. Can be used to | ||
submit forms and file uploads to other web applications. | ||
A module to create readable ```"multipart/form-data"``` streams. Can be used to submit forms and file uploads to other web applications. | ||
The API of this module is inspired by the | ||
[XMLHttpRequest-2 FormData Interface][xhr2-fd]. | ||
The API of this module is inspired by the [XMLHttpRequest-2 FormData Interface][xhr2-fd]. | ||
@@ -140,2 +138,6 @@ [xhr2-fd]: http://dev.w3.org/2006/webapi/XMLHttpRequest-2/Overview.html#the-formdata-interface | ||
## Notes | ||
- ```getLengthSync()``` method DOESN'T calculate length for streams, use ```knownLength``` options as workaround. | ||
## TODO | ||
@@ -142,0 +144,0 @@ |
14172
255
149
Updatedasync@~0.2.9
Updatedmime@~1.2.9