Skip to content

Commit

Permalink
Merge pull request #20 from Ircam-RnD/master
Browse files Browse the repository at this point in the history
fix/hack to send progress datas total, loaded and lengthComputable
  • Loading branch information
ykzts committed Oct 16, 2014
2 parents 6be96e0 + 3e72d57 commit dc67355
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/xmlhttprequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,15 @@
_properties.responseHeaders = response.headers;
contentLength = response.headers['content-length'] || contentLength;
bufferLength = parseInt(contentLength, 10);
this.lengthComputable = false;
if(bufferLength !== 0){
this.total = bufferLength;
this.loaded = 0;
this.lengthComputable = true;
}
_properties.responseBuffer = new Buffer(bufferLength);
_readyStateChange.call(this, XMLHttpRequest.LOADING);
var that = this;
response.addListener('data', function(chunk) {
var buffer;
if (bufferLength === 0) {
Expand All @@ -337,6 +344,7 @@
}
chunk.copy(this._properties.responseBuffer, byteOffset);
byteOffset += chunk.length;
that.loaded = byteOffset;
_readyStateChange.call(this, XMLHttpRequest.LOADING);
}.bind(this));
response.addListener('end', function() {
Expand All @@ -349,7 +357,8 @@
var loadStartEvent = new ProgressEvent('loadstart');
this.dispatchEvent(loadStartEvent);
stream.on('data', function() {
var progressEvent = new ProgressEvent('progress');
var progress = {lengthComputable: this.lengthComputable, total: this.total, loaded: this.loaded};
var progressEvent = new ProgressEvent('progress', progress);
this.dispatchEvent(progressEvent);
}.bind(this));
stream.on('end', function() {
Expand Down Expand Up @@ -439,7 +448,7 @@

proto.setRequestHeader = function setRequestHeader(header, value) {
if (this.readyState === XMLHttpRequest.UNSENT) {
throw new Error(''); // todo
throw new Error(''); // todo
}
if (forbiddenRequestHeaders.test(header)) return;
this._properties.requestHeaders[header] = value;
Expand Down

0 comments on commit dc67355

Please sign in to comment.