lib/localPersistence/localPersistenceManager.js
/**
   * Copy levels from disk to memory using a Node Streams at the management level.
   *
   * @private
   */
Copy levels from disk to memory using a Node Streams at the management level.
@private
Copy levels from disk to memory using a Node Streams at the management level . @private
async copyLevelsToMemory() {
    this.logger.debug('Initializing database clone in memory...');
    const tmpMemoryLevels = new Map();
    const tmpManagementLevel = this.managementLevel;
    const tmpDB = this.db;
    const tmpLogger = this.logger;
    const managementLevelReadableStream = tmpManagementLevel.createKeyStream();
    const managementLevelWritableStream = Writable({
      async write(key, encoding, cb) {
        const sublevelOptions = await tmpManagementLevel.get(key);
        tmpLogger.debug(`Cloning ${key.toString()} level in memory...`);
        const sublevel = subleveldown(tmpDB, key.toString(), sublevelOptions);
        const memoryLevel = levelup(encodedown(memdown(), sublevelOptions));
        tmpMemoryLevels.set(key.toString(), memoryLevel);
        await LocalPersistenceManager.copyLevel(sublevel, memoryLevel);
        cb();
      },
    });
    try {
      await pipelineAsync(
        managementLevelReadableStream,
        managementLevelWritableStream,
      );
    } catch (error) {
      this.logger.info(error);
    }
    this.memoryLevels = tmpMemoryLevels;
  }
async copyLevelsToMemory ( ) { this . logger . debug ( 'Initializing database clone in memory...' ) ; const tmpMemoryLevels = new Map ( ) ; const tmpManagementLevel = this . managementLevel ; const tmpDB = this . db ; const tmpLogger = this . logger ; const managementLevelReadableStream = tmpManagementLevel . createKeyStream ( ) ; const managementLevelWritableStream = Writable ( { async write ( key , encoding , cb ) { const sublevelOptions = await tmpManagementLevel . get ( key ) ; tmpLogger . debug ( ` ${ key . toString ( ) } ` ) ; const sublevel = subleveldown ( tmpDB , key . toString ( ) , sublevelOptions ) ; const memoryLevel = levelup ( encodedown ( memdown ( ) , sublevelOptions ) ) ; tmpMemoryLevels . set ( key . toString ( ) , memoryLevel ) ; await LocalPersistenceManager . copyLevel ( sublevel , memoryLevel ) ; cb ( ) ; } , } ) ; try { await pipelineAsync ( managementLevelReadableStream , managementLevelWritableStream , ) ; } catch ( error ) { this . logger . info ( error ) ; } this . memoryLevels = tmpMemoryLevels ; }
Copy levels from disk to memory using a Node Streams at the management level.
Copy levels from disk to memory using a Node Streams at the management level .