( file, chunkSize )
| 2979 | |
| 2980 | // 负责将文件切片。 |
| 2981 | function CuteFile( file, chunkSize ) { |
| 2982 | var pending = [], |
| 2983 | blob = file.source, |
| 2984 | total = blob.size, |
| 2985 | chunks = chunkSize ? Math.ceil( total / chunkSize ) : 1, |
| 2986 | start = 0, |
| 2987 | index = 0, |
| 2988 | len, api; |
| 2989 | |
| 2990 | api = { |
| 2991 | file: file, |
| 2992 | |
| 2993 | has: function() { |
| 2994 | return !!pending.length; |
| 2995 | }, |
| 2996 | |
| 2997 | shift: function() { |
| 2998 | return pending.shift(); |
| 2999 | }, |
| 3000 | |
| 3001 | unshift: function( block ) { |
| 3002 | pending.unshift( block ); |
| 3003 | } |
| 3004 | }; |
| 3005 | |
| 3006 | while ( index < chunks ) { |
| 3007 | len = Math.min( chunkSize, total - start ); |
| 3008 | |
| 3009 | pending.push({ |
| 3010 | file: file, |
| 3011 | start: start, |
| 3012 | end: chunkSize ? (start + len) : total, |
| 3013 | total: total, |
| 3014 | chunks: chunks, |
| 3015 | chunk: index++, |
| 3016 | cuted: api |
| 3017 | }); |
| 3018 | start += len; |
| 3019 | } |
| 3020 | |
| 3021 | file.blocks = pending.concat(); |
| 3022 | file.remaning = pending.length; |
| 3023 | |
| 3024 | return api; |
| 3025 | } |
| 3026 | |
| 3027 | Uploader.register({ |
| 3028 | name: 'upload', |
no outgoing calls
no test coverage detected