persist.js
/*      outcome/
 * Load all the logs we find in a
 * given location. We expect this
 * location to be 'ours' and so all
 * files in it should be our log
 * (shards).
 */
outcome
Load all the logs we find in a
given location. We expect this
location to be 'ours' and so all
files in it should be our log
(shards).
outcome Load all the logs we find in a given location . We expect this location to be ' ours ' and so all files in it should be our log ( shards ) .
function loadFrom(folder, cb) {
    fs.readdir(folder, (err, files) => {
        if(err) {
            if(err.code == 'ENOENT') cb()
            else cb(err)
        } else {
            let paths = files.map((f) => path.join(folder, f))
            load_shards_1(paths, (err, shards) => {
                if(err) cb(err)
                else cb(null, shards)
            })
        }
    })
    function load_shards_1(paths, cb) {
        let shards = []
        load_path_ndx_1(0)
        function load_path_ndx_1(ndx) {
            if(ndx >= paths.length) cb(null, shards)
            else {
                let file = paths[ndx]
                if(isShardFileName(file)) {
                    deserialize(file, (err, shard) => {
                        if(err) cb(err)
                        else {
                            shards.push(shard)
                            load_path_ndx_1(ndx+1)
                        }
                    })
                } else {
                    load_path_ndx_1(ndx+1)
                }
            }
        }
    }
}
function loadFrom ( folder , cb ) { fs . readdir ( folder , ( err , files ) => { if ( err ) { if ( err . code == 'ENOENT' ) cb ( ) else cb ( err ) } else { let paths = files . map ( ( f ) => path . join ( folder , f ) ) load_shards_1 ( paths , ( err , shards ) => { if ( err ) cb ( err ) else cb ( null , shards ) } ) } } ) function load_shards_1 ( paths , cb ) { let shards = [ ] load_path_ndx_1 ( 0 ) function load_path_ndx_1 ( ndx ) { if ( ndx >= paths . length ) cb ( null , shards ) else { let file = paths [ ndx ] if ( isShardFileName ( file ) ) { deserialize ( file , ( err , shard ) => { if ( err ) cb ( err ) else { shards . push ( shard ) load_path_ndx_1 ( ndx + 1 ) } } ) } else { load_path_ndx_1 ( ndx + 1 ) } } } } }
outcome
 Load all the logs we find in a
 given location.
outcome Load all the logs we find in a given location .