What is @syncfusion/ej2-compression?
@syncfusion/ej2-compression is a package that provides functionalities for compressing and decompressing files and data streams. It is part of the Syncfusion Essential JS 2 suite and is designed to work seamlessly with other Syncfusion components.
What are @syncfusion/ej2-compression's main functionalities?
File Compression
This feature allows you to compress files into a ZIP archive. The code sample demonstrates how to create a ZIP archive and add a file to it, then save the archive to a specified path.
const { ZipArchive, ZipArchiveItem } = require('@syncfusion/ej2-compression');
let archive = new ZipArchive();
archive.addItem(new ZipArchiveItem('path/to/file.txt', 'file.txt'));
archive.save('path/to/archive.zip');
File Decompression
This feature allows you to decompress files from a ZIP archive. The code sample demonstrates how to load a ZIP archive and extract all its contents to a specified directory.
const { ZipArchive } = require('@syncfusion/ej2-compression');
let archive = new ZipArchive();
archive.load('path/to/archive.zip');
archive.extractAll('path/to/extract');
Stream Compression
This feature allows you to compress data streams into a ZIP archive. The code sample demonstrates how to create a ZIP archive and add a file stream to it, then save the archive to a specified path.
const { ZipArchive, ZipArchiveItem } = require('@syncfusion/ej2-compression');
const fs = require('fs');
let archive = new ZipArchive();
let readStream = fs.createReadStream('path/to/file.txt');
archive.addItem(new ZipArchiveItem(readStream, 'file.txt'));
archive.save('path/to/archive.zip');
Stream Decompression
This feature allows you to decompress data streams from a ZIP archive. The code sample demonstrates how to load a ZIP archive and extract a specific file to a write stream.
const { ZipArchive } = require('@syncfusion/ej2-compression');
const fs = require('fs');
let archive = new ZipArchive();
archive.load('path/to/archive.zip');
let writeStream = fs.createWriteStream('path/to/extract/file.txt');
archive.extractItem('file.txt', writeStream);
Other packages similar to @syncfusion/ej2-compression
adm-zip
ADM-ZIP is a pure JavaScript implementation for ZIP file management. It provides functionalities for reading, creating, and updating ZIP files. Compared to @syncfusion/ej2-compression, ADM-ZIP is more focused on ZIP file manipulation and is widely used in the Node.js community.
yazl
Yazl is a ZIP file creation library for Node.js. It is designed to be fast and efficient, with a focus on streaming data into ZIP files. Compared to @syncfusion/ej2-compression, Yazl is more lightweight and specialized in ZIP file creation.
yauzl
Yauzl is a ZIP file reading library for Node.js. It is designed to be fast and efficient, with a focus on streaming data out of ZIP files. Compared to @syncfusion/ej2-compression, Yauzl is more lightweight and specialized in ZIP file reading.