tasks/cloudfiles.js
function hashFile(filename, callback) {

    var calledBack = false,
        md5sum = crypto.createHash('md5'),
        stream = fs.ReadStream(filename);

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

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

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

    function handleResponse(err, hash) {
      if (calledBack) {
        return;
      }

      calledBack = true;
      callback(err, hash);
    }
  }
function hashFile(filename, callback) {

    var calledBack = false,
        md5sum = crypto.createHash('md5'),
        stream = fs.ReadStream(filename);

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

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

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

    function handleResponse(err, hash) {
      if (calledBack) {
        return;
      }

      calledBack = true;
      callback(err, hash);
    }
  }
function hashFile ( filename , callback ) { var calledBack = false , md5sum = crypto . createHash ( 'md5' ) , stream = fs . ReadStream ( filename ) ; stream . on ( 'data' , function ( data ) { md5sum . update ( data ) ; } ) ; stream . on ( 'end' , function ( ) { var hash = md5sum . digest ( 'hex' ) ; callback ( null , hash ) ; } ) ; stream . on ( 'error' , function ( err ) { handleResponse ( err ) ; } ) ; function handleResponse ( err , hash ) { if ( calledBack ) { return ; } calledBack = true ; callback ( err , hash ) ; } }
Used to MD5 a file, useful when checking against already uploaded assets
Used to MD5 a file useful when checking against already uploaded assets