( file, chunkSize )
| 3916 | |
| 3917 | // 负责将文件切片。 |
| 3918 | function CuteFile( file, chunkSize ) { |
| 3919 | var pending = [], |
| 3920 | blob = file.source, |
| 3921 | total = blob.size, |
| 3922 | chunks = chunkSize ? Math.ceil( total / chunkSize ) : 1, |
| 3923 | start = 0, |
| 3924 | index = 0, |
| 3925 | len, api; |
| 3926 | |
| 3927 | api = { |
| 3928 | file: file, |
| 3929 | |
| 3930 | has: function() { |
| 3931 | return !!pending.length; |
| 3932 | }, |
| 3933 | |
| 3934 | shift: function() { |
| 3935 | return pending.shift(); |
| 3936 | }, |
| 3937 | |
| 3938 | unshift: function( block ) { |
| 3939 | pending.unshift( block ); |
| 3940 | } |
| 3941 | }; |
| 3942 | |
| 3943 | while ( index < chunks ) { |
| 3944 | len = Math.min( chunkSize, total - start ); |
| 3945 | |
| 3946 | pending.push({ |
| 3947 | file: file, |
| 3948 | start: start, |
| 3949 | end: chunkSize ? (start + len) : total, |
| 3950 | total: total, |
| 3951 | chunks: chunks, |
| 3952 | chunk: index++, |
| 3953 | cuted: api |
| 3954 | }); |
| 3955 | start += len; |
| 3956 | } |
| 3957 | |
| 3958 | file.blocks = pending.concat(); |
| 3959 | file.remaning = pending.length; |
| 3960 | |
| 3961 | return api; |
| 3962 | } |
| 3963 | |
| 3964 | Uploader.register({ |
| 3965 | name: 'upload', |
no outgoing calls
no test coverage detected