I am struggling with this code:

All with:
                                http.createServer( function( req,res) {}
wrapped around...               

If I do this, Chrome and Internet Explorer keep blank:

                                var raw = fs.createReadStream(filePath);
         var encoding = 'deflate' ;
         raw.pipe(zlib.createDeflate()).pipe(res);
         res.writeHead(200, {
  'content-encoding' : encoding, 
  'Content-Type': contentType + '; charset=utf-8' 
});
res.end()

If I do this, Chrome loads, IE fails:

                                var raw = fs.createReadStream(filePath);
         var encoding = 'deflate' ;
         raw.pipe(zlib.createDeflate()).pipe(res);
         res.writeHead(200, {
  'content-encoding' : encoding, 
  'Content-Type': contentType + '; charset=utf-8' 
});
If I do this, there is no "end" event on the "res"

                                var raw = fs.createReadStream(filePath);
         var encoding = 'deflate' ;
         raw.pipe(zlib.createDeflate()).pipe(res);
         res.writeHead(200, {
  'content-encoding' : encoding, 
  'Content-Type': contentType + '; charset=utf-8' 
});
res.on('end', res.end )

If I do this, the server crashes with:
  -  http.js:919

    this._implicitHeader();

         ^

TypeError: Object #<ReadStream> has no method '_implicitHeader'

    at ReadStream.OutgoingMessage.end (http.js:919:10)

    at ReadStream.emit (events.js:117:20)

    at _stream_readable.js:944:16

    at process._tickCallback (node.js:442:13)
                                var raw = fs.createReadStream(filePath);
         var encoding = 'deflate' ;
         raw.pipe(zlib.createDeflate()).pipe(res);
         res.writeHead(200, {
  'content-encoding' : encoding, 
  'Content-Type': contentType + '; charset=utf-8' 
});
raw.on('end', res.end )


I am in the know about the Node.js documentation, where it says:
  -  "The method, response.end(), MUST be called on each response."
http://nodejs.org/api/http.html#http_response_end_data_encoding_callback
...


What can I do?

-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/a2853319-d336-4689-abdb-cb37456609ca%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to