image-bin-compressor
v1.0.4
Published
A simple image compressor using node.js which take binary buffer as input and return compressed binary buffer as output
Downloads
6
Readme
image-bin-compressor
A simple Node.js utility designed to be used with Multer in server-side applications to compress data. It offers lossless compression using the gzip algorithm.
Multer implementation
example usage, please refer to the EXAMPLE.md file.
Installation
You can install the package via npm:
npm install image-bin-compressor
Importing the Module
import { compressBinaryData, decompressBinaryData } from 'image-bin-compressor';
Compressing Binary Data
// binaryData is a Buffer containing the raw binary data of the image
const compressedData = await compressBinaryData(binaryData);
// Decompressing Binary Data
// compressedData is a Buffer containing the compressed binary data
const decompressedData = await decompressBinaryData(compressedData);
Example
import { compressBinaryData, decompressBinaryData } from 'image-bin-compressor';
import fs from 'fs';
async function example() {
try {
// Read binary data from file
const binaryData = fs.readFileSync('image.jpg');
// Compress binary data
const compressedData = await compressBinaryData(binaryData);
// Decompress compressed data
const decompressedData = await decompressBinaryData(compressedData);
// Compare original binary data with decompressed data
console.log('Are original binary data and decompressed data equal?', Buffer.compare(binaryData, decompressedData) === 0);
} catch (error) {
console.error('Error:', error);
}
}
example();