Skip to content

Instantly share code, notes, and snippets.

@thebergamo
Created September 17, 2014 14:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save thebergamo/f93cbdd529f01c8ee4ad to your computer and use it in GitHub Desktop.
Save thebergamo/f93cbdd529f01c8ee4ad to your computer and use it in GitHub Desktop.
var file = __dirname + '/../upload/'+ req.payload.code+'.jpg';
fs.exists(file, function(exists){
if(!exists)
res(Boom.notFound('Image not found'));
var fd = fs.openSync(file, 'r');
var end = new Buffer(4);
fs.readSync(fd, end, 0, 4, 0);
var name = new Buffer(end.readUInt32LE(0));
fs.readSync(fd, name, 0, end.readUInt32LE(0), 4);
fs.closeSync(fd);
fs.createReadStrean(file, {
start: end.readUInt32LE(0) + 4
}).pipe(res);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment