image-utility-library
Version:
A Node.js library for compressing, resizing, cropping, and applying effects to images.
28 lines (22 loc) • 775 B
JavaScript
import { createWriteStream } from 'fs';
import archiver from 'archiver';
/**
* Export multiple images into a ZIP archive.
* @param {Array} images - Array of objects { name: String, buffer: Buffer }.
* @param {String} outputPath - Output path for the ZIP file.
* @returns {Promise<void>}
*/
const exportAsZip = async (images, outputPath) => {
const output = createWriteStream(outputPath);
const archive = archiver('zip', { zlib: { level: 9 } });
return new Promise((resolve, reject) => {
archive.pipe(output);
images.forEach((img) => {
archive.append(img.buffer, { name: img.name });
});
archive.finalize();
output.on('close', resolve);
archive.on('error', reject);
});
};
export default exportAsZip;