A simple utility for unzipping files in Node.js. This library allows you to unzip files and list the contents of the extracted directory.
You can install the package via npm:
npm install @letladi/unzipimport { unzip } from '@letladi/unzip';
async function example() {
try {
const { extractedFolderPath, files } = await unzip('path/to/your/file.zip', 'path/to/extract/');
console.log('Files extracted to:', extractedFolderPath);
console.log('Extracted files:', files);
} catch (error) {
console.error('An error occurred:', error);
}
}
example();import { unzip } from '@letladi/unzip';
async function example() {
try {
const { extractedFolderPath, files } = await unzip('path/to/your/file.zip');
console.log('Files extracted to:', extractedFolderPath);
console.log('Extracted files:', files);
} catch (error) {
console.error('An error occurred:', error);
}
}
example();
import { unzip } from '@letladi/unzip';
// Example 1: Using .then() and .catch()
unzip('path/to/your/file.zip', 'path/to/extract/')
.then(({ extractedFolderPath, files }) => {
console.log('Files extracted to:', extractedFolderPath);
console.log('Extracted files:', files);
})
.catch((error) => {
console.error('An error occurred:', error);
});
// Example 2: Using .then() and .catch() with default extraction path
unzip('path/to/your/file.zip')
.then(({ extractedFolderPath, files }) => {
console.log('Files extracted to:', extractedFolderPath);
console.log('Extracted files:', files);
})
.catch((error) => {
console.error('An error occurred:', error);
});filePath: The path to the zip file you want to unzip.extractfilePath: (optional): The path where the contents should be extracted. If not provided, a unique directory name will be generated.
extractedFolderPath: The path to the folder where the files were extracted.files: An array of file paths of the extracted files.
The unzip function will throw an error if:
- The zip file cannot be found or opened.
- There is an issue during the extraction process.
To contribute or modify the library:
-
Clone the repository. -
Install dependencies: npm install -
Build the project: npm run build -
Run tests: npm test
build: Compiles TypeScript code into JavaScript.test: Runs tests using Jest.clean-up: Cleans up temporary files after tests.
This project is licensed under the MIT License.
Created by Letladi Sebesho.