Skip to content

Commit 655b959

Browse files
committed
Added hasKnownLength public method
#196 #262
1 parent 652b16f commit 655b959

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

lib/form_data.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ FormData.prototype.getLengthSync = function() {
325325
}
326326

327327
// https://github.com/form-data/form-data/issues/40
328-
if (this._valuesToMeasure.length) {
328+
if (!this.hasKnownLength()) {
329329
// Some async length retrievers are present
330330
// therefore synchronous length calculation is false.
331331
// Please use getLength(callback) to get proper length
@@ -335,6 +335,19 @@ FormData.prototype.getLengthSync = function() {
335335
return knownLength;
336336
};
337337

338+
// Public API to check if length of added values is known
339+
// https://github.com/form-data/form-data/issues/196
340+
// https://github.com/form-data/form-data/issues/262
341+
FormData.prototype.hasKnownLength = function() {
342+
var hasKnownLength = true;
343+
344+
if (this._valuesToMeasure.length) {
345+
hasKnownLength = false;
346+
}
347+
348+
return hasKnownLength;
349+
};
350+
338351
FormData.prototype.getLength = function(cb) {
339352
var knownLength = this._overheadLength + this._valueLength;
340353

0 commit comments

Comments
 (0)