SORU
8 EKİM 2010, Cuma


Node.js: sıkıştırma Gzip?

Node.js hayır gzip sıkıştırma yapar ve orada modülleri gzip sıkıştırma gerçekleştirmek için vardır hiçbir bulgu olarak, yanlış mıyım? Nasıl bir kimse sıkıştırma yok olan bir web sunucusu kullanabilir mi? Burada neyi kaçırıyorum? İzlemeye çalışayım-gasp-port sunucu tarafı JavaScript için algoritma kullanmak?

CEVAP
11 ŞUBAT 2012, CUMARTESİ


Düğüm v0.6.x şimdi çekirdek zlib module stabil - o-yan sunucu dokümanlar da kullanmak için bazı örnekler var.

(Docs alınan) bir örnek:

// server example
// Running a gzip operation on every request is quite expensive.
// It would be much more efficient to cache the compressed buffer.
var zlib = require('zlib');
var http = require('http');
var fs = require('fs');
http.createServer(function(request, response) {
  var raw = fs.createReadStream('index.html');
  var acceptEncoding = request.headers['accept-encoding'];
  if (!acceptEncoding) {
    acceptEncoding = '';
  }

  // Note: this is not a conformant accept-encoding parser.
  // See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.3
  if (acceptEncoding.match(/\bdeflate\b/)) {
    response.writeHead(200, { 'content-encoding': 'deflate' });
    raw.pipe(zlib.createDeflate()).pipe(response);
  } else if (acceptEncoding.match(/\bgzip\b/)) {
    response.writeHead(200, { 'content-encoding': 'gzip' });
    raw.pipe(zlib.createGzip()).pipe(response);
  } else {
    response.writeHead(200, {});
    raw.pipe(response);
  }
}).listen(1337);

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Chanre Joubert

    Chanre Joube

    27 Temmuz 2012
  • justintimberlakeVEVO

    justintimber

    2 EYLÜL 2009
  • tseyina

    tseyina

    2 AĞUSTOS 2006