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

box / boxcli / 5794698568

pending completion
5794698568

Pull #488

github

web-flow
Merge 96c25857d into 3bc6a83f7
Pull Request #488: docs: Update docs after release 3.9.2

1113 of 1441 branches covered (77.24%)

Branch coverage included in aggregate %.

4135 of 4633 relevant lines covered (89.25%)

468.81 hits per line

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

79.25
/src/commands/files/zip.js
1
'use strict';
2

3
const BoxCommand = require('../../box-command');
12✔
4
const { flags } = require('@oclif/command');
12✔
5
const fs = require('fs');
12✔
6
const path = require('path');
12✔
7
const utils = require('../../util');
12✔
8

9
class FilesZipCommand extends BoxCommand {
10
        async run() {
11
                const { flags, args } = this.parse(FilesZipCommand);
48✔
12

13
                let fileName = args.name;
48✔
14
                if (!fileName.includes('.zip')) {
48!
15
                        fileName += '.zip';
×
16
                }
17

18
                let filePath;
19

20
                if (flags.destination) {
48✔
21
                        await utils.checkDir(flags.destination, flags['create-path']);
24✔
22
                        filePath = path.join(flags.destination, fileName);
24✔
23
                } else {
24
                        filePath = path.join(this.settings.boxDownloadsFolderPath, fileName);
24✔
25
                }
26

27
                /* eslint-disable no-sync */
28
                if (!flags.overwrite && fs.existsSync(filePath)) {
48!
29
                /* eslint-enable no-sync */
30

31
                        let shouldOverwrite = await this.confirm(`File ${filePath} already exists — overwrite?`);
×
32

33
                        if (!shouldOverwrite) {
×
34
                                return;
×
35
                        }
36
                }
37

38
                let output = fs.createWriteStream(filePath);
48✔
39

40
                let downloadStatus;
41
                let outputFinished = false;
48✔
42
                /* eslint-disable promise/avoid-new */
43
                await new Promise((resolve, reject) => {
48✔
44
                        /* eslint-disable promise/always-return */
45
                        this.client.files.downloadZip(fileName, flags.item, output).then((status) => {
48✔
46
                                downloadStatus = status;
48✔
47
                                if (outputFinished) {
48!
48
                                        resolve();
48✔
49
                                }
50
                        })
51
                        .catch(reject);
52
                        output.on('close', () => {
48✔
53
                                output.close();
48✔
54
                                outputFinished = true;
48✔
55
                                if (downloadStatus) {
48!
56
                                        resolve();
×
57
                                }
58
                        });
59
                        output.on('error', reject);
48✔
60
                });
61
                await this.output(downloadStatus);
48✔
62
        }
63
}
64

65
FilesZipCommand.description = 'Create a zip of multiple files and folders and download it';
12✔
66
FilesZipCommand.examples = ['box files:zip sample_file.zip --item=file:12421 --item=folder:48291'];
12✔
67
FilesZipCommand._endpoint = 'zip_downloads';
12✔
68

69
FilesZipCommand.flags = {
12✔
70
        ...BoxCommand.flags,
71
        destination: flags.string({
72
                description: 'The destination folder to write the zip file to',
73
                parse: utils.parsePath,
74
        }),
75
        item: flags.string({
76
                description:
77
                        'Files or folders to be part of zip in the form type:ID (i.e. file:1374652)',
78
                multiple: true,
79
                required: true,
80
                parse(val) {
81
                        let splitVal = val.split(':');
192✔
82
                        return { type: splitVal[0], id: splitVal[1] };
192✔
83
                },
84
        }),
85
        'create-path': flags.boolean({
86
                description: 'Recursively creates a path to a directory if it does not exist',
87
                allowNo: true,
88
                default: true,
89
        }),
90
        overwrite: flags.boolean({
91
                description: 'Overwrite a zip file if it already exists',
92
                allowNo: true,
93
                default: false
94
        }),
95
};
96

97
FilesZipCommand.args = [
12✔
98
        {
99
                name: 'name',
100
                required: true,
101
                hidden: false,
102
                description: 'Name of the zip to be created and downloaded',
103
        }
104
];
105

106
module.exports = FilesZipCommand;
12✔
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

© 2025 Coveralls, Inc