@@ -122,7 +122,6 @@ ZipImagePlayer.prototype = {
122
122
}
123
123
} ,
124
124
_load : function ( offset , length , callback ) {
125
- var end = offset + length ;
126
125
var _this = this ;
127
126
// Unfortunately JQuery doesn't support ArrayBuffer XHR
128
127
var xhr = new XMLHttpRequest ( ) ;
@@ -132,27 +131,40 @@ ZipImagePlayer.prototype = {
132
131
}
133
132
_this . _debugLog ( "Load: " + offset + " " + length + " status=" +
134
133
xhr . status ) ;
135
- if ( xhr . status != 206 ) {
136
- _this . _error ( "Unexpected HTTP status " + xhr . status ) ;
137
- }
138
- if ( xhr . response . byteLength != length ) {
139
- _this . _error ( "Unexpected length " + xhr . response . byteLength +
140
- " (expected " + length + ")" ) ;
134
+ if ( xhr . status == 200 ) {
135
+ _this . _debugLog ( "Range disabled or unsupported, complete load" ) ;
136
+ offset = 0 ;
137
+ length = xhr . response . byteLength ;
138
+ _this . _len = length ;
139
+ _this . _buf = xhr . response ;
140
+ _this . _bytes = new _this . _Uint8Array ( _this . _buf ) ;
141
+ } else {
142
+ if ( xhr . status != 206 ) {
143
+ _this . _error ( "Unexpected HTTP status " + xhr . status ) ;
144
+ }
145
+ if ( xhr . response . byteLength != length ) {
146
+ _this . _error ( "Unexpected length " +
147
+ xhr . response . byteLength +
148
+ " (expected " + length + ")" ) ;
149
+ }
150
+ _this . _bytes . set ( new _this . _Uint8Array ( xhr . response ) , offset ) ;
141
151
}
142
- _this . _bytes . set ( new _this . _Uint8Array ( xhr . response ) , offset ) ;
143
152
if ( callback ) {
144
- callback . apply ( _this ) ;
153
+ callback . apply ( _this , [ offset , length ] ) ;
145
154
}
146
155
} , false ) ;
147
156
xhr . addEventListener ( "error" , this . _mkerr ( "Fetch failed" ) , false ) ;
148
157
xhr . open ( "GET" , this . op . source ) ;
149
158
xhr . responseType = "arraybuffer" ;
150
- xhr . setRequestHeader ( "Range" , "bytes=" + offset + "-" + ( end - 1 ) ) ;
151
- if ( this . _isSafari ) {
152
- // Range request caching is broken in Safari
153
- // https://bugs.webkit.org/show_bug.cgi?id=82672
154
- xhr . setRequestHeader ( "Cache-control" , "no-cache" ) ;
155
- xhr . setRequestHeader ( "If-None-Match" , Math . random ( ) . toString ( ) ) ;
159
+ if ( offset != null && length != null ) {
160
+ var end = offset + length ;
161
+ xhr . setRequestHeader ( "Range" , "bytes=" + offset + "-" + ( end - 1 ) ) ;
162
+ if ( this . _isSafari ) {
163
+ // Range request caching is broken in Safari
164
+ // https://bugs.webkit.org/show_bug.cgi?id=82672
165
+ xhr . setRequestHeader ( "Cache-control" , "no-cache" ) ;
166
+ xhr . setRequestHeader ( "If-None-Match" , Math . random ( ) . toString ( ) ) ;
167
+ }
156
168
}
157
169
/*this._debugLog("Load: " + offset + " " + length);*/
158
170
xhr . send ( ) ;
@@ -171,9 +183,19 @@ ZipImagePlayer.prototype = {
171
183
if ( _this . _dead ) {
172
184
return ;
173
185
}
186
+ _this . _pHead = 0 ;
187
+ _this . _pNextHead = 0 ;
188
+ _this . _pFetch = 0 ;
174
189
var len = parseInt ( xhr . getResponseHeader ( "Content-Length" ) ) ;
175
190
if ( ! len ) {
176
- _this . _error ( "Invalid file length" ) ;
191
+ _this . _debugLog ( "HEAD request failed: invalid file length." ) ;
192
+ _this . _debugLog ( "Falling back to full file mode." ) ;
193
+ _this . _load ( null , null , function ( off , len ) {
194
+ _this . _pTail = 0 ;
195
+ _this . _pHead = len ;
196
+ _this . _findCentralDirectory ( ) ;
197
+ } ) ;
198
+ return ;
177
199
}
178
200
_this . _debugLog ( "Len: " + len ) ;
179
201
_this . _len = len ;
@@ -183,11 +205,8 @@ ZipImagePlayer.prototype = {
183
205
if ( off < 0 ) {
184
206
off = 0 ;
185
207
}
186
- _this . _pHead = 0 ;
187
- _this . _pNextHead = 0 ;
188
208
_this . _pTail = len ;
189
- _this . _pFetch = 0 ;
190
- _this . _load ( off , len - off , function ( ) {
209
+ _this . _load ( off , len - off , function ( off , len ) {
191
210
_this . _pTail = off ;
192
211
_this . _findCentralDirectory ( ) ;
193
212
} ) ;
@@ -244,9 +263,10 @@ ZipImagePlayer.prototype = {
244
263
this . _pHead = this . _len ;
245
264
$ ( this ) . triggerHandler ( "loadProgress" , [ this . _pHead / this . _len ] ) ;
246
265
this . _loadNextFrame ( ) ;
266
+ } else {
267
+ this . _loadNextChunk ( ) ;
268
+ this . _loadNextChunk ( ) ;
247
269
}
248
- this . _loadNextChunk ( ) ;
249
- this . _loadNextChunk ( ) ;
250
270
} ,
251
271
_loadNextChunk : function ( ) {
252
272
if ( this . _pFetch >= this . _pTail ) {
0 commit comments