( file, chunkSize )
| 3184 | |
| 3185 | // 负责将文件切片。 |
| 3186 | function CuteFile( file, chunkSize ) { |
| 3187 | var pending = [], |
| 3188 | blob = file.source, |
| 3189 | total = blob.size, |
| 3190 | chunks = chunkSize ? Math.ceil( total / chunkSize ) : 1, |
| 3191 | start = 0, |
| 3192 | index = 0, |
| 3193 | len, api; |
| 3194 | |
| 3195 | api = { |
| 3196 | file: file, |
| 3197 | |
| 3198 | has: function() { |
| 3199 | return !!pending.length; |
| 3200 | }, |
| 3201 | |
| 3202 | shift: function() { |
| 3203 | return pending.shift(); |
| 3204 | }, |
| 3205 | |
| 3206 | unshift: function( block ) { |
| 3207 | pending.unshift( block ); |
| 3208 | } |
| 3209 | }; |
| 3210 | |
| 3211 | while ( index < chunks ) { |
| 3212 | len = Math.min( chunkSize, total - start ); |
| 3213 | |
| 3214 | pending.push({ |
| 3215 | file: file, |
| 3216 | start: start, |
| 3217 | end: chunkSize ? (start + len) : total, |
| 3218 | total: total, |
| 3219 | chunks: chunks, |
| 3220 | chunk: index++, |
| 3221 | cuted: api |
| 3222 | }); |
| 3223 | start += len; |
| 3224 | } |
| 3225 | |
| 3226 | file.blocks = pending.concat(); |
| 3227 | file.remaning = pending.length; |
| 3228 | |
| 3229 | return api; |
| 3230 | } |
| 3231 | |
| 3232 | Uploader.register({ |
| 3233 | name: 'upload', |
no outgoing calls
no test coverage detected