Skip to content

Instantly share code, notes, and snippets.

@alanhoff
Forked from thebergamo/teste.js
Last active August 29, 2015 14:06
Show Gist options
  • Select an option

  • Save alanhoff/1188ca75ed0cb3ffce80 to your computer and use it in GitHub Desktop.

Select an option

Save alanhoff/1188ca75ed0cb3ffce80 to your computer and use it in GitHub Desktop.

Revisions

  1. alanhoff revised this gist Sep 17, 2014. 1 changed file with 1 addition and 5 deletions.
    6 changes: 1 addition & 5 deletions teste.js
    Original file line number Diff line number Diff line change
    @@ -4,9 +4,5 @@ fs.exists(file, function(exists){
    if(!exists)
    return res(Boom.notFound('Image not found'));

    var stream = fs.createReadStream(file);
    var response = new Hapi.response.Stream(stream);

    response.type('text/csv');
    request.reply(response);
    res.file(file);
    });
  2. alanhoff revised this gist Sep 17, 2014. 1 changed file with 5 additions and 6 deletions.
    11 changes: 5 additions & 6 deletions teste.js
    Original file line number Diff line number Diff line change
    @@ -1,13 +1,12 @@
    var file = __dirname + '/../upload/'+ req.payload.code+'.jpg';

    fs.exists(file, function(exists){
    if(!exists)
    return res(Boom.notFound('Image not found'));
    if(!exists)
    return res(Boom.notFound('Image not found'));

    var stream = fs.createReadStream(file);
    var stream = fs.createReadStream(file);
    var response = new Hapi.response.Stream(stream);

    response.type('text/csv');
    request.reply(response);

    response.type('text/csv');
    request.reply(response);
    });
  3. alanhoff revised this gist Sep 17, 2014. 1 changed file with 10 additions and 6 deletions.
    16 changes: 10 additions & 6 deletions teste.js
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,13 @@
    var file = __dirname + '/../upload/'+ req.payload.code+'.jpg';
    var file = __dirname + '/../upload/'+ req.payload.code+'.jpg';

    fs.exists(file, function(exists){
    if(!exists)
    res(Boom.notFound('Image not found'));
    fs.exists(file, function(exists){
    if(!exists)
    return res(Boom.notFound('Image not found'));

    fs.createReadStrean(file).pipe(res);
    var stream = fs.createReadStream(file);
    var response = new Hapi.response.Stream(stream);

    });
    response.type('text/csv');
    request.reply(response);

    });
  4. alanhoff revised this gist Sep 17, 2014. 1 changed file with 1 addition and 13 deletions.
    14 changes: 1 addition & 13 deletions teste.js
    Original file line number Diff line number Diff line change
    @@ -4,18 +4,6 @@
    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);
    fs.createReadStrean(file).pipe(res);

    });
  5. @thebergamo thebergamo created this gist Sep 17, 2014.
    21 changes: 21 additions & 0 deletions teste.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    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);

    });