lib/JsonIndex.js
function () {
    return new Promise((resolve, reject) => {
      var startTime = Date.now();
      var size = fs.statSync(dataFile).size;
      var next = (readInfo, position) => {
        var jobs = [readNextChunk(readInfo)];

        if (position) {
          jobs.push(readAndIndex(position, readInfo.readBuffer));
          debug(position);
        }

        Q.all(jobs).then(results => {
          var nextReadInfo = results[0];
          var nextPosition = results[1] || {};

          readInfo.readBuffer = null;

          if (nextReadInfo.done && position) {
            debug("indexSize size: %s", (indexSize / 1024) + "KB");
            debug("index ready (took %s secs)", (Date.now() - startTime) / 1000);

            meta.size = indexSize;

            debug(meta);

            resolve();
          } else {
            next(nextReadInfo, nextPosition);
          }
        }).catch(err => reject(err));
      };

      debug("creating index");
      next({ size: size, fd: openDataFile() });
    });
  }
function () {
    return new Promise((resolve, reject) => {
      var startTime = Date.now();
      var size = fs.statSync(dataFile).size;
      var next = (readInfo, position) => {
        var jobs = [readNextChunk(readInfo)];

        if (position) {
          jobs.push(readAndIndex(position, readInfo.readBuffer));
          debug(position);
        }

        Q.all(jobs).then(results => {
          var nextReadInfo = results[0];
          var nextPosition = results[1] || {};

          readInfo.readBuffer = null;

          if (nextReadInfo.done && position) {
            debug("indexSize size: %s", (indexSize / 1024) + "KB");
            debug("index ready (took %s secs)", (Date.now() - startTime) / 1000);

            meta.size = indexSize;

            debug(meta);

            resolve();
          } else {
            next(nextReadInfo, nextPosition);
          }
        }).catch(err => reject(err));
      };

      debug("creating index");
      next({ size: size, fd: openDataFile() });
    });
  }
function ( ) { return new Promise ( ( resolve , reject ) => { var startTime = Date . now ( ) ; var size = fs . statSync ( dataFile ) . size ; var next = ( readInfo , position ) => { var jobs = [ readNextChunk ( readInfo ) ] ; if ( position ) { jobs . push ( readAndIndex ( position , readInfo . readBuffer ) ) ; debug ( position ) ; } Q . all ( jobs ) . then ( results => { var nextReadInfo = results [ 0 ] ; var nextPosition = results [ 1 ] || { } ; readInfo . readBuffer = null ; if ( nextReadInfo . done && position ) { debug ( "indexSize size: %s" , ( indexSize / 1024 ) + "KB" ) ; debug ( "index ready (took %s secs)" , ( Date . now ( ) - startTime ) / 1000 ) ; meta . size = indexSize ; debug ( meta ) ; resolve ( ) ; } else { next ( nextReadInfo , nextPosition ) ; } } ) . catch ( err => reject ( err ) ) ; } ; debug ( "creating index" ) ; next ( { size : size , fd : openDataFile ( ) } ) ; } ) ; }
Creates the index. The index consist of a map from a user-specific key to
the position within the buffer where the item starts and ends. Items are
read lazily when it is required.
Creates the index . The index consist of a map from a user - specific key to the position within the buffer where the item starts and ends . Items are read lazily when it is required .