Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8548869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:35:49+00:00 2026-06-11T13:35:49+00:00

I need to compress a buffer in Node.js with zlib at the extreme compression

  • 0

I need to compress a buffer in Node.js with zlib at the extreme compression level. The outputted header should be 78 DA. Unless I’m missing something, the Node.js documentation doesn’t really describe how to use the zlib.Deflate class. It doesn’t accept any parameters.

http://nodejs.org/api/zlib.html#zlib_class_zlib_deflate

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T13:35:51+00:00Added an answer on June 11, 2026 at 1:35 pm

    Use zlib. createGzip/createDeflate to get an instance of the compressor you need, with options in an object.

    If you want to do this all in-memory:

    var zlib = require('zlib');
    
    // create a new gzip object
    var gzip = zlib.createGzip({
        level: 9 // maximum compression
    }), buffers=[], nread=0;
    
    // attach event handlers...
    
    gzip.on('error', function(err) {
        gzip.removeAllListeners();
        gzip=null;
    });
    
    gzip.on('data', function(chunk) {
        buffers.push(chunk);
        nread += chunk.length;
    });
    
    
    gzip.on('end', function() {
        var buffer;
        switch (buffers.length) {
            case 0: // no data.  return empty buffer
                buffer = new Buffer(0);
                break;
            case 1: // only one chunk of data.  return it.
                buffer = buffers[0];
                break;
            default: // concatenate the chunks of data into a single buffer.
                buffer = new Buffer(nread);
                var n = 0;
                buffers.forEach(function(b) {
                    var l = b.length;
                    b.copy(buffer, n, 0, l);
                    n += l;
                });
                break;
        }
    
        gzip.removeAllListeners();
        gzip=null;
    
        // do something with `buffer` here!
    });
    
    // and finally, give it data to compress
    gzip.write(inputBuffer);
    gzip.end();
    

    Of course, if you’re dealing with large amounts of data, stream the output to a file rather than buffering everything in memory.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to choose a compression algorithm to compress some data. I don't know
I found the zlib and gzip decompression algorithms, but I need to compress a
I am using django-compress for compression . According to need I want to change
I need to compress my data folder using 7zip (compression mode store) from my
I am using the zlib to compress data but I need to create a
I need to compress some binary files as quickly as possible with PHP -
I need to compress a string to reduce the size of a web service
For a scientific project i need to compress video data. The video however doesn't
I have LOTS of logs and I need to compress them in a weekly
I have around 2 million strings with different lengths that I need to compress

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.