MCPcopy Create free account
hub / github.com/TruthHun/BookStack / CuteFile

Function CuteFile

static/webuploader/webuploader.custom.js:3489–3533  ·  view source on GitHub ↗
( file, chunkSize )

Source from the content-addressed store, hash-verified

3487
3488 // 负责将文件切片。
3489 function CuteFile( file, chunkSize ) {
3490 var pending = [],
3491 blob = file.source,
3492 total = blob.size,
3493 chunks = chunkSize ? Math.ceil( total / chunkSize ) : 1,
3494 start = 0,
3495 index = 0,
3496 len, api;
3497
3498 api = {
3499 file: file,
3500
3501 has: function() {
3502 return !!pending.length;
3503 },
3504
3505 shift: function() {
3506 return pending.shift();
3507 },
3508
3509 unshift: function( block ) {
3510 pending.unshift( block );
3511 }
3512 };
3513
3514 while ( index < chunks ) {
3515 len = Math.min( chunkSize, total - start );
3516
3517 pending.push({
3518 file: file,
3519 start: start,
3520 end: chunkSize ? (start + len) : total,
3521 total: total,
3522 chunks: chunks,
3523 chunk: index++,
3524 cuted: api
3525 });
3526 start += len;
3527 }
3528
3529 file.blocks = pending.concat();
3530 file.remaning = pending.length;
3531
3532 return api;
3533 }
3534
3535 Uploader.register({
3536 name: 'upload',

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected