( file, chunkSize )
| 2958 | |
| 2959 | // 负责将文件切片。 |
| 2960 | function CuteFile( file, chunkSize ) { |
| 2961 | var pending = [], |
| 2962 | blob = file.source, |
| 2963 | total = blob.size, |
| 2964 | chunks = chunkSize ? Math.ceil( total / chunkSize ) : 1, |
| 2965 | start = 0, |
| 2966 | index = 0, |
| 2967 | len, api; |
| 2968 | |
| 2969 | api = { |
| 2970 | file: file, |
| 2971 | |
| 2972 | has: function() { |
| 2973 | return !!pending.length; |
| 2974 | }, |
| 2975 | |
| 2976 | shift: function() { |
| 2977 | return pending.shift(); |
| 2978 | }, |
| 2979 | |
| 2980 | unshift: function( block ) { |
| 2981 | pending.unshift( block ); |
| 2982 | } |
| 2983 | }; |
| 2984 | |
| 2985 | while ( index < chunks ) { |
| 2986 | len = Math.min( chunkSize, total - start ); |
| 2987 | |
| 2988 | pending.push({ |
| 2989 | file: file, |
| 2990 | start: start, |
| 2991 | end: chunkSize ? (start + len) : total, |
| 2992 | total: total, |
| 2993 | chunks: chunks, |
| 2994 | chunk: index++, |
| 2995 | cuted: api |
| 2996 | }); |
| 2997 | start += len; |
| 2998 | } |
| 2999 | |
| 3000 | file.blocks = pending.concat(); |
| 3001 | file.remaning = pending.length; |
| 3002 | |
| 3003 | return api; |
| 3004 | } |
| 3005 | |
| 3006 | Uploader.register({ |
| 3007 | name: 'upload', |
no outgoing calls
no test coverage detected