Merge pull request #2013 from yurydelendik/fix-server-length
Fixing the channel offset value and length given by HTTP headers
This commit is contained in:
		
						commit
						62e6b434b9
					
				| @ -131,12 +131,14 @@ function PdfDataListener(length) { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| PdfDataListener.prototype = { | PdfDataListener.prototype = { | ||||||
|   set: function PdfDataListener_set(chunk, offset) { |   append: function PdfDataListener_append(chunk) { | ||||||
|     if (this.length < 0) { |  | ||||||
|     var willBeLoaded = this.loaded + chunk.length; |     var willBeLoaded = this.loaded + chunk.length; | ||||||
|  |     if (this.length >= 0 && this.length < willBeLoaded) { | ||||||
|  |       this.length = -1; // reset the length, server is giving incorrect one
 | ||||||
|  |     } | ||||||
|  |     if (this.length < 0 && this.data.length < willBeLoaded) { | ||||||
|       // data length is unknown and new chunk will not fit in the existing
 |       // data length is unknown and new chunk will not fit in the existing
 | ||||||
|       // buffer, resizing the buffer by doubling the its last length
 |       // buffer, resizing the buffer by doubling the its last length
 | ||||||
|       if (this.data.length < willBeLoaded) { |  | ||||||
|       var newLength = this.data.length; |       var newLength = this.data.length; | ||||||
|       for (; newLength < willBeLoaded; newLength *= 2) {} |       for (; newLength < willBeLoaded; newLength *= 2) {} | ||||||
|       var newData = new Uint8Array(newLength); |       var newData = new Uint8Array(newLength); | ||||||
| @ -145,15 +147,13 @@ PdfDataListener.prototype = { | |||||||
|     } |     } | ||||||
|     this.data.set(chunk, this.loaded); |     this.data.set(chunk, this.loaded); | ||||||
|     this.loaded = willBeLoaded; |     this.loaded = willBeLoaded; | ||||||
|     } else { |     if (this.length >= 0) | ||||||
|       this.data.set(chunk, offset); |  | ||||||
|       this.loaded = offset + chunk.length; |  | ||||||
|       this.onprogress(this.loaded, this.length); |       this.onprogress(this.loaded, this.length); | ||||||
|     } |  | ||||||
|   }, |   }, | ||||||
|   getData: function PdfDataListener_getData() { |   getData: function PdfDataListener_getData() { | ||||||
|     var data = this.length >= 0 ? this.data : |     var data = this.data; | ||||||
|                                   this.data.subarray(0, this.loaded); |     if (this.loaded != data.length) | ||||||
|  |       data = data.subarray(0, this.loaded); | ||||||
|     delete this.data; // releasing temporary storage
 |     delete this.data; // releasing temporary storage
 | ||||||
|     return data; |     return data; | ||||||
|   }, |   }, | ||||||
| @ -462,7 +462,7 @@ PdfStreamConverter.prototype = { | |||||||
| 
 | 
 | ||||||
|     var binaryStream = this.binaryStream; |     var binaryStream = this.binaryStream; | ||||||
|     binaryStream.setInputStream(aInputStream); |     binaryStream.setInputStream(aInputStream); | ||||||
|     this.dataListener.set(binaryStream.readByteArray(aCount), aOffset); |     this.dataListener.append(binaryStream.readByteArray(aCount)); | ||||||
|   }, |   }, | ||||||
| 
 | 
 | ||||||
|   // nsIRequestObserver::onStartRequest
 |   // nsIRequestObserver::onStartRequest
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user