compress
Compress files or directories into ZIP archives with configurable compression levels, password protection, and encryption options.
Instructions
Compress local files or directories into a ZIP file
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| input | Yes | File path(s) or directory to compress | |
| output | Yes | Output ZIP file path | |
| options | No |
Implementation Reference
- src/index.ts:173-225 (handler)The implementation of the 'compress' tool handler which takes file/directory paths and creates a ZIP file.
case "compress": { const input = args.input as string | string[]; const output = args.output as string; const options = (args.options as any) || {}; if (fs.existsSync(output) && !options.overwrite) { throw new Error(`Output file already exists: ${output}`); } const zip = new AdmZip(); const inputs = Array.isArray(input) ? input : [input]; for (const inputPath of inputs) { if (!fs.existsSync(inputPath)) { throw new Error(`Input path does not exist: ${inputPath}`); } const stats = fs.statSync(inputPath); if (stats.isDirectory()) { zip.addLocalFolder(inputPath, path.basename(inputPath)); } else { zip.addLocalFile(inputPath); } } if (options.comment) { zip.addZipComment(options.comment); } zip.writeZip(output); const outputStats = fs.statSync(output); return { content: [ { type: "text", text: JSON.stringify( { success: true, output: output, size: outputStats.size, files: zip.getEntries().length, }, null, 2, ), }, ], }; } - src/index.ts:27-76 (schema)The schema definition for the 'compress' tool.
{ name: "compress", description: "Compress local files or directories into a ZIP file", inputSchema: { type: "object", properties: { input: { anyOf: [ { type: "string" }, { type: "array", items: { type: "string" } }, ], description: "File path(s) or directory to compress", }, output: { type: "string", description: "Output ZIP file path", }, options: { type: "object", properties: { overwrite: { type: "boolean", description: "Overwrite if output file exists", }, level: { type: "number", description: "Compression level (0-9)", minimum: 0, maximum: 9, }, password: { type: "string", description: "Password to encrypt ZIP file", }, comment: { type: "string", description: "ZIP file comment", }, encryptionStrength: { type: "number", enum: [1, 2, 3], description: "Encryption strength (1=AES-128, 2=AES-192, 3=AES-256)", }, }, }, }, required: ["input", "output"], }, },