Giter Site home page Giter Site logo

Comments (6)

Fishrock123 avatar Fishrock123 commented on March 29, 2024

That is zlib's concern, I believe.

from compression.

dougwilson avatar dougwilson commented on March 29, 2024

The way you can do this is simply to wrap this middleware, just like any middleware.

Simple example:

var compression = require('compression')
var express = require('express')

express.use(variableCompression())

function variableCompression() {
  var compressors = Object.create(null)

  return function (req, res, next) {
    if (!should_compress) { // should_compress is up to you
      next()
      return
    }

    var level = get_compression_level() // get_compression_level is up to you
    var compressor = compressors[level] || (compressors[level] = compression({level: level}))

    compressor(req, res, next)
  }
}

from compression.

ilanbiala avatar ilanbiala commented on March 29, 2024

@dougwilson thanks for the start, does zlib handle any of that, or I have to? Any ideas on how to get memory consumption percentage through node?

from compression.

dougwilson avatar dougwilson commented on March 29, 2024

does zlib handle any of that, or I have to?

I really don't know :/

Any ideas on how to get memory consumption percentage through node?

I've never tried to do that, so I'm not sure off-hand. There is an os.totalmem() and os.freemem() in the os module (http://nodejs.org/api/os.html) that you could probably use.

from compression.

ilanbiala avatar ilanbiala commented on March 29, 2024

@dougwilson thanks for the help!

from compression.

dougwilson avatar dougwilson commented on March 29, 2024

No problem :) Feel free to continue to ask follow ups on this issue, btw.

from compression.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.