( file, chunkSize )
| 3386 | |
| 3387 | // 负责将文件切片。 |
| 3388 | function CuteFile( file, chunkSize ) { |
| 3389 | var pending = [], |
| 3390 | blob = file.source, |
| 3391 | total = blob.size, |
| 3392 | chunks = chunkSize ? Math.ceil( total / chunkSize ) : 1, |
| 3393 | start = 0, |
| 3394 | index = 0, |
| 3395 | len, api; |
| 3396 | |
| 3397 | api = { |
| 3398 | file: file, |
| 3399 | |
| 3400 | has: function() { |
| 3401 | return !!pending.length; |
| 3402 | }, |
| 3403 | |
| 3404 | shift: function() { |
| 3405 | return pending.shift(); |
| 3406 | }, |
| 3407 | |
| 3408 | unshift: function( block ) { |
| 3409 | pending.unshift( block ); |
| 3410 | } |
| 3411 | }; |
| 3412 | |
| 3413 | while ( index < chunks ) { |
| 3414 | len = Math.min( chunkSize, total - start ); |
| 3415 | |
| 3416 | pending.push({ |
| 3417 | file: file, |
| 3418 | start: start, |
| 3419 | end: chunkSize ? (start + len) : total, |
| 3420 | total: total, |
| 3421 | chunks: chunks, |
| 3422 | chunk: index++, |
| 3423 | cuted: api |
| 3424 | }); |
| 3425 | start += len; |
| 3426 | } |
| 3427 | |
| 3428 | file.blocks = pending.concat(); |
| 3429 | file.remaning = pending.length; |
| 3430 | |
| 3431 | return api; |
| 3432 | } |
| 3433 | |
| 3434 | Uploader.register({ |
| 3435 | name: 'upload', |
no outgoing calls
no test coverage detected