Socket
Book a DemoInstallSign in
Socket

image-bin-compressor

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

image-bin-compressor

A simple image compressor using node.js which take binary buffer as input and return compressed binary buffer as output

latest
npmnpm
Version
1.0.4
Version published
Maintainers
1
Created
Source

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();

FAQs

Package last updated on 18 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts