• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

box / boxcli / 23065353910

13 Mar 2026 06:37PM UTC coverage: 84.083% (+0.02%) from 84.064%
23065353910

Pull #646

github

web-flow
Merge e408c0c2c into fd0d6aee0
Pull Request #646: docs: Update descriptions for ai commands

1427 of 1946 branches covered (73.33%)

Branch coverage included in aggregate %.

23 of 27 new or added lines in 13 files covered. (85.19%)

78 existing lines in 4 files now uncovered.

4912 of 5593 relevant lines covered (87.82%)

625.42 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

46.43
/src/modules/upload.js
1
'use strict';
2

3
const fs = require('node:fs');
9✔
4
const progress = require('cli-progress');
9✔
5
const BoxCLIError = require('../cli-error');
9✔
6

7
const CHUNKED_UPLOAD_FILE_SIZE = 1024 * 1024 * 100; // 100 MiB
9✔
8

9
function createReadStream(filePath) {
10
        try {
108✔
11
                return fs.createReadStream(filePath);
108✔
12
        } catch (error) {
13
                throw new BoxCLIError(`Could not open file ${filePath}`, error);
×
14
        }
15
}
16

17
function runChunkedUpload(uploader, size) {
18
        const progressBar = new progress.Bar({
×
19
                format: '[{bar}] {percentage}% | ETA: {eta_formatted} | {value}/{total} | Speed: {speed} MB/s',
20
                stopOnComplete: true,
21
        });
22
        let bytesUploaded = 0;
×
23
        const startTime = Date.now();
×
24
        progressBar.start(size, 0, { speed: 'N/A' });
×
25
        uploader.on('chunkUploaded', (chunk) => {
×
26
                bytesUploaded += chunk.part.size;
×
27
                progressBar.update(bytesUploaded, {
×
28
                        speed: Math.floor(bytesUploaded / (Date.now() - startTime) / 1000),
29
                });
30
        });
UNCOV
31
        return uploader.start();
×
32
}
33

34
async function uploadFile(
35
        client,
36
        { folderID, name, stream, size, fileAttributes }
37
) {
38
        if (size < CHUNKED_UPLOAD_FILE_SIZE) {
72!
39
                return client.files.uploadFile(folderID, name, stream, fileAttributes);
72✔
40
        }
UNCOV
41
        const uploader = await client.files.getChunkedUploader(
×
42
                folderID,
43
                size,
44
                name,
45
                stream,
46
                { fileAttributes }
47
        );
UNCOV
48
        return runChunkedUpload(uploader, size);
×
49
}
50

51
async function uploadNewFileVersion(
52
        client,
53
        { fileID, stream, size, fileAttributes }
54
) {
55
        if (size < CHUNKED_UPLOAD_FILE_SIZE) {
36!
56
                return client.files.uploadNewFileVersion(
36✔
57
                        fileID,
58
                        stream,
59
                        fileAttributes
60
                );
61
        }
UNCOV
62
        const uploader = await client.files.getNewVersionChunkedUploader(
×
63
                fileID,
64
                size,
65
                stream,
66
                { fileAttributes }
67
        );
UNCOV
68
        return runChunkedUpload(uploader, size);
×
69
}
70

71
module.exports = {
9✔
72
        CHUNKED_UPLOAD_FILE_SIZE,
73
        createReadStream,
74
        uploadFile,
75
        uploadNewFileVersion,
76
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc