lib/rsync/rsync-utils.js
function blockChecksums(fs, path, size, callback) {
  var cache = {};

  fs.readFile(path, function (err, data) {
    if (!err) {
      // cache file
      cache[path] = data;
    } else if (err && err.code === 'ENOENT') {
      cache[path] = [];
    } else {
      return callback(err);
    }

    var length = cache[path].length;
    var incr = size;
    var start = 0;
    var end = incr > length ? length : incr;
    var blockIndex = 0;
    var result = [];
    var chunk;
    var weak;
    var strong;

    while (start < length) {
      chunk  = cache[path].slice(start, end);
      weak   = calcWeak32(chunk).sum;
      strong = md5sum(chunk);

      result.push({
        index: blockIndex,
        weak: weak,
        strong: strong
      });
      // update slice indices
      start += incr;
      end = (end + incr) > length ? length : end + incr;
      // update block index
      blockIndex++;
    }

    callback(null, result);
  });
}
function blockChecksums(fs, path, size, callback) {
  var cache = {};

  fs.readFile(path, function (err, data) {
    if (!err) {
      // cache file
      cache[path] = data;
    } else if (err && err.code === 'ENOENT') {
      cache[path] = [];
    } else {
      return callback(err);
    }

    var length = cache[path].length;
    var incr = size;
    var start = 0;
    var end = incr > length ? length : incr;
    var blockIndex = 0;
    var result = [];
    var chunk;
    var weak;
    var strong;

    while (start < length) {
      chunk  = cache[path].slice(start, end);
      weak   = calcWeak32(chunk).sum;
      strong = md5sum(chunk);

      result.push({
        index: blockIndex,
        weak: weak,
        strong: strong
      });
      // update slice indices
      start += incr;
      end = (end + incr) > length ? length : end + incr;
      // update block index
      blockIndex++;
    }

    callback(null, result);
  });
}
function blockChecksums ( fs , path , size , callback ) { var cache = { } ; fs . readFile ( path , function ( err , data ) { if ( ! err ) { // cache file cache [ path ] = data ; } else if ( err && err . code === 'ENOENT' ) { cache [ path ] = [ ] ; } else { return callback ( err ) ; } var length = cache [ path ] . length ; var incr = size ; var start = 0 ; var end = incr > length ? length : incr ; var blockIndex = 0 ; var result = [ ] ; var chunk ; var weak ; var strong ; while ( start < length ) { chunk = cache [ path ] . slice ( start , end ) ; weak = calcWeak32 ( chunk ) . sum ; strong = md5sum ( chunk ) ; result . push ( { index : blockIndex , weak : weak , strong : strong } ) ; // update slice indices start += incr ; end = ( end + incr ) > length ? length : end + incr ; // update block index blockIndex ++ ; } callback ( null , result ) ; } ) ; }
Rsync function to calculate checksums for a file by dividing it into blocks of data whose size is passed in and checksuming each block of data
Rsync function to calculate checksums for a file by dividing it into blocks of data whose size is passed in and checksuming each block of data