Skip to content

Instantly share code, notes, and snippets.

@shimondoodkin
Created July 10, 2010 14:28
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 shimondoodkin/470742 to your computer and use it in GitHub Desktop.
Save shimondoodkin/470742 to your computer and use it in GitHub Desktop.
var fs = require('fs');
var http = require('http');
var Buffer = require('buffer').Buffer;
var gif;
fs.readFile(__filename, function (err, data)
{
if (err) throw err;
gif = new Buffer(data, 'utf8');
});
http.createServer(function (req, res)
{
res.writeHead(200, {'Content-Type' : 'image/gif'});
req.setEncoding('binary');
res.write(gif);
res.end();
// Do db magic after the request is sent.
}).listen(91);
----
simple script same error
/var/www/nodejs-mongodb-app/files_page.js:8
gif = new Buffer(data, 'utf8');
^
TypeError: Bad argument
at /var/www/nodejs-mongodb-app/files_page.js:8:9
at fs:83:13
at node.js:255:9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment