| 3361 | |
| 3362 | // 负责将文件切片。 |
| 3363 | function CuteFile( file, chunkSize ) { |
| 3364 | var pending = [], |
| 3365 | blob = file.source, |
| 3366 | total = blob.size, |
| 3367 | chunks = chunkSize ? Math.ceil( total / chunkSize ) : 1, |
| 3368 | start = 0, |
| 3369 | index = 0, |
| 3370 | len, api; |
| 3371 | |
| 3372 | api = { |
| 3373 | file: file, |
| 3374 | |
| 3375 | has: function() { |
| 3376 | return !!pending.length; |
| 3377 | }, |
| 3378 | |
| 3379 | shift: function() { |
| 3380 | return pending.shift(); |
| 3381 | }, |
| 3382 | |
| 3383 | unshift: function( block ) { |
| 3384 | pending.unshift( block ); |
| 3385 | } |
| 3386 | }; |
| 3387 | |
| 3388 | while ( index < chunks ) { |
| 3389 | len = Math.min( chunkSize, total - start ); |
| 3390 | |
| 3391 | pending.push({ |
| 3392 | file: file, |
| 3393 | start: start, |
| 3394 | end: chunkSize ? (start + len) : total, |
| 3395 | total: total, |
| 3396 | chunks: chunks, |
| 3397 | chunk: index++, |
| 3398 | cuted: api |
| 3399 | }); |
| 3400 | start += len; |
| 3401 | } |
| 3402 | |
| 3403 | file.blocks = pending.concat(); |
| 3404 | file.remaning = pending.length; |
| 3405 | |
| 3406 | return api; |
| 3407 | } |
| 3408 | |
| 3409 | Uploader.register({ |
| 3410 | name: 'upload', |