0

So i'm having trouble trying to return a value from the constructor of this module. I literally have no idea how to return a value back to the constructor.

I hope the code is self-explanatory, i want the constructor to return the hash variable.

var Fiber = require('fibers');
var Future = require('fibers/future'), wait = Future.wait;

var fs = require('fs')
var crypto = require('crypto')



exports.cryptFile = function(fileName, callback){

    var crypt = crypto.createHash('md5');

    var stream = fs.ReadStream(fileName, {
        bufferSize: 1024 * 1024
    });


    stream.on('data', function(data) {
        crypt.update(data)
    });

    stream.on('error', function(err) {
        callback(err);
    });

    stream.on('end', function(){
        var digest = crypt.digest('hex')
        callback(null, digest);
    });



}

var cryptFileFuture = Future.wrap(this.cryptFile);


module.exports = function(filename){
    var future = new Future;
    Fiber(function(){
        hash = cryptFileFuture(filename).wait();
        console.log(hash);
        future.return(hash);
    });
    return future;
//  return hash;
}
Manak Kapoor
  • 962
  • 3
  • 12
  • 21
  • I think you may just be missing .run() from the end of the fiber. https://github.com/laverdet/node-Fibers – Jake Jan 12 '14 at 03:04

1 Answers1

0

you forgot the .run() on on the Fiber

Micha Roon
  • 3,957
  • 2
  • 30
  • 48