Skip to content

Commit aa00fe4

Browse files
committed
Fixing the length given by HTTP headers
1 parent c16a6ae commit aa00fe4

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

extensions/firefox/components/PdfStreamConverter.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -132,28 +132,28 @@ function PdfDataListener(length) {
132132

133133
PdfDataListener.prototype = {
134134
set: function PdfDataListener_set(chunk, offset) {
135-
if (this.length < 0) {
136-
var willBeLoaded = this.loaded + chunk.length;
135+
var willBeLoaded = this.loaded + chunk.length;
136+
if (this.length >= 0 && this.length < willBeLoaded) {
137+
this.length = -1; // reset the length, server is giving incorrect one
138+
}
139+
if (this.length < 0 && this.data.length < willBeLoaded) {
137140
// data length is unknown and new chunk will not fit in the existing
138141
// buffer, resizing the buffer by doubling the its last length
139-
if (this.data.length < willBeLoaded) {
140-
var newLength = this.data.length;
141-
for (; newLength < willBeLoaded; newLength *= 2) {}
142-
var newData = new Uint8Array(newLength);
143-
newData.set(this.data);
144-
this.data = newData;
145-
}
146-
this.data.set(chunk, this.loaded);
147-
this.loaded = willBeLoaded;
148-
} else {
149-
this.data.set(chunk, offset);
150-
this.loaded = offset + chunk.length;
151-
this.onprogress(this.loaded, this.length);
142+
var newLength = this.data.length;
143+
for (; newLength < willBeLoaded; newLength *= 2) {}
144+
var newData = new Uint8Array(newLength);
145+
newData.set(this.data);
146+
this.data = newData;
152147
}
148+
this.data.set(chunk, this.loaded);
149+
this.loaded = willBeLoaded;
150+
if (this.length >= 0)
151+
this.onprogress(this.loaded, this.length);
153152
},
154153
getData: function PdfDataListener_getData() {
155-
var data = this.length >= 0 ? this.data :
156-
this.data.subarray(0, this.loaded);
154+
var data = this.data;
155+
if (this.loaded != data.length)
156+
data = data.subarray(0, this.loaded);
157157
delete this.data; // releasing temporary storage
158158
return data;
159159
},

0 commit comments

Comments
 (0)