blocks.js
function readInteger(width, reader) {
    return function (start, cb) {
      var i = Math.floor(start/block_size)
      var _i = start%block_size

      //if the UInt32BE aligns with in a block
      //read directly and it's 3x faster.
      if(_i < block_size - width)
        get(i, function (err, block) {
          if(err) return cb(err)
          var value = reader(block, start%block_size)
          cb(null, value)
        })
      //but handle overlapping reads this easier way
      //instead of messing around with bitwise ops
      else
        read(start, start+width, function (err, buf, bytes_read) {
          if(err) return cb(err)
          var value = reader(buf, 0);
          cb(isNaN(value) ? new Error('Number is too large') : null, value)
        })
    }
  }
function readInteger(width, reader) {
    return function (start, cb) {
      var i = Math.floor(start/block_size)
      var _i = start%block_size

      //if the UInt32BE aligns with in a block
      //read directly and it's 3x faster.
      if(_i < block_size - width)
        get(i, function (err, block) {
          if(err) return cb(err)
          var value = reader(block, start%block_size)
          cb(null, value)
        })
      //but handle overlapping reads this easier way
      //instead of messing around with bitwise ops
      else
        read(start, start+width, function (err, buf, bytes_read) {
          if(err) return cb(err)
          var value = reader(buf, 0);
          cb(isNaN(value) ? new Error('Number is too large') : null, value)
        })
    }
  }
function readInteger ( width , reader ) { return function ( start , cb ) { var i = Math . floor ( start / block_size ) var _i = start % block_size //if the UInt32BE aligns with in a block //read directly and it's 3x faster. if ( _i < block_size - width ) get ( i , function ( err , block ) { if ( err ) return cb ( err ) var value = reader ( block , start % block_size ) cb ( null , value ) } ) //but handle overlapping reads this easier way //instead of messing around with bitwise ops else read ( start , start + width , function ( err , buf , bytes_read ) { if ( err ) return cb ( err ) var value = reader ( buf , 0 ) ; cb ( isNaN ( value ) ? new Error ( 'Number is too large' ) : null , value ) } ) } }
start by reading the end of the last block. this must always be kept in memory.
start by reading the end of the last block . this must always be kept in memory .