@@ -132,28 +132,28 @@ function PdfDataListener(length) {
132
132
133
133
PdfDataListener .prototype = {
134
134
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 ) {
137
140
// data length is unknown and new chunk will not fit in the existing
138
141
// 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 ;
152
147
}
148
+ this .data .set (chunk , this .loaded );
149
+ this .loaded = willBeLoaded ;
150
+ if (this .length >= 0 )
151
+ this .onprogress (this .loaded , this .length );
153
152
},
154
153
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 );
157
157
delete this .data ; // releasing temporary storage
158
158
return data ;
159
159
},
0 commit comments