Cross-platform Zip/Unzip CLI
cross-zip-cli is a command-line interface wrapper for the `cross-zip` library, designed to provide consistent cross-platform directory zipping and unzipping capabilities. It exposes two main commands: `cross-zip` for compression and `cross-unzip` for decompression. This tool is particularly valuable for developers writing `npm` scripts or other automated build processes that need to function identically across Windows, macOS, and Linux environments, abstracting away the underlying operating system's native archiving utilities. The current stable version is 1.0.0, and it appears to be in a maintenance state with no recent updates since 2021. Its primary differentiator is its focus on simplifying cross-platform archival tasks within automated workflows, ensuring reliability and compatibility regardless of the host OS.
Common errors
-
'cross-zip' is not recognized as an internal or external command, operable program or batch file.
cause The `cross-zip` command (or `cross-unzip`) is not found in your system's PATH. This typically happens if the package was installed locally and you are not calling it via `npx` or the `./node_modules/.bin` directory, or if a global installation failed.fixIf installed locally, use `npx cross-zip` or run it from `$(npm bin)/cross-zip`. For global access, ensure it's installed globally with `npm install -g cross-zip-cli` and that your npm global bin directory is in your system's PATH. -
Error: Input directory does not exist: /path/to/nonexistent
cause The source directory specified for zipping with `cross-zip` does not exist at the provided path.fixVerify that the input directory path is correct and that the directory actually exists before running the `cross-zip` command. -
Error: zip file not found: /path/to/nonexistent.zip
cause The source zip file specified for unzipping with `cross-unzip` does not exist at the provided path.fixVerify that the input zip file path is correct and that the file actually exists before running the `cross-unzip` command. -
Error: Cannot create zip file: EACCES: permission denied, open '/path/to/output.zip'
cause The user executing the command does not have sufficient write permissions to create the output zip file or directory at the specified destination.fixChange the output directory to one where the current user has write permissions, or adjust the file system permissions for the target directory.
Warnings
- gotcha When installing, `cross-zip-cli` is primarily designed for global installation (`npm install -g cross-zip-cli`) or execution via `npx` (e.g., `npx cross-zip-cli`). If installed locally without using `npx`, the commands may not be directly available in your shell's PATH without specifying `./node_modules/.bin/cross-zip`.
- gotcha Paths containing spaces must be enclosed in double quotes (e.g., `"./my folder/data"`) when passed as arguments to `cross-zip` or `cross-unzip`, especially on Windows, to prevent misinterpretation of the arguments.
- gotcha The `cross-zip-cli` tool currently does not provide a progress indicator during zipping or unzipping operations. For very large directories or files, the command may appear to hang, leading to uncertainty about its status.
- gotcha By default, `cross-zip` will overwrite an existing destination zip file without prompting. This can lead to unintended data loss if the target file path is already in use.
Install
-
npm install cross-zip-cli -
yarn add cross-zip-cli -
pnpm add cross-zip-cli
Imports
- cross-zip
import { crossZip } from 'cross-zip-cli';n/a (CLI executable)
- cross-unzip
const crossUnzip = require('cross-zip-cli').unzip;n/a (CLI executable)
- Package Root
import crossZipCli from 'cross-zip-cli';
n/a (CLI package)
Quickstart
{}
{
"name": "my-project",
"version": "1.0.0",
"scripts": {
"install-cli": "npm install -g cross-zip-cli",
"create-test-dir": "mkdir -p ./temp/data && echo 'Hello, world!' > ./temp/data/hello.txt && echo 'Another file.' > ./temp/data/another.txt",
"zip-data": "cross-zip ./temp/data ./temp/archive.zip",
"unzip-data": "cross-unzip ./temp/archive.zip ./temp/extracted",
"clean": "rm -rf ./temp"
}
}
```
```bash
# Install the CLI globally (or use npx for local execution)
npm run install-cli
# Create a dummy directory with files
npm run create-test-dir
# Zip the 'data' directory into 'archive.zip'
npm run zip-data
# Unzip 'archive.zip' into a new 'extracted' directory
npm run unzip-data
# Clean up temporary files
npm run clean
```