2013-10-25 31 views
9

Aşağıdaki kodda, gziplenmiş bir URL'nin isteğini ilettiğim yere sahibim. Bu iyi çalışır, ancak kodu birkaç kez çalıştırmaya çalışırsam, aşağıdaki hatayı alıyorum. Bu konuda nasıl çalışacağınıza dair herhangi bir öneriniz var mı?Node.js hatadan sonra yazılır zlib

Teşekkür ederiz!

http.get(url, function(req) { 

    req.pipe(gunzip); 

    gunzip.on('data', function (data) { 
    decoder.decode(data); 
    }); 

    gunzip.on('end', function() { 
    decoder.result(); 
    }); 

}); 

Hata: yazılabilir akışı kapatıldığında

stack: 
    [ 'Error: write after end', 
    ' at writeAfterEnd (_stream_writable.js:125:12)', 
    ' at Gunzip.Writable.write (_stream_writable.js:170:5)', 
    ' at write (_stream_readable.js:547:24)', 
    ' at flow (_stream_readable.js:556:7)', 
    ' at _stream_readable.js:524:7', 
    ' at process._tickCallback (node.js:415:13)' ] } 
+0

'req' olmalıdır' res' –

cevap

18

, artık kabul edilemez verileri (see the documentation): Birinci yürütme üzerinde kod çalışacak, işte bu yüzden ve saniye size' write after end hata verecek.

Hemen her istek için yeni bir gunzip akışı oluşturmak:

http.get(url, function(req) { 
    var gunzip = zlib.createGzip(); 
    req.pipe(gunzip); 

    gunzip.on('data', function (data) { 
    decoder.decode(data); 
    }); 

    gunzip.on('end', function() { 
    decoder.result(); 
    }); 

}); 
İlgili konular