Skip to content

Instantly share code, notes, and snippets.

@geddski
Created December 14, 2012 23:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geddski/4289608 to your computer and use it in GitHub Desktop.
Save geddski/4289608 to your computer and use it in GitHub Desktop.
example of gzipping files manually in Node
var http = require('http');
var fs = require('fs');
var zlib = require('zlib');
http.createServer(function (req, res) {
// var img = fs.readFileSync('./bird.jpg');
var img = fs.createReadStream('./public/bird.jpg');
// res.writeHead(200, {'Content-Type': 'image/jpeg'});
res.writeHead(200, { 'content-encoding': 'gzip' });
// res.end(img, 'binary');
img.pipe(zlib.createGzip({level: 9})).pipe(res);
}).listen(8080, '127.0.0.1');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment