scripts/configure.js
function unpack(filename, callback, entryCallback) {
    var input = fs.createReadStream(filename, { flags: 'r', encoding: null }),
        files = {},
        dir = path.dirname(filename),
        returned = false,
        to = null;

    // Finishs the unpack if all files are done
    function maybeFinish() {
        if (to !== null) clearTimeout(to);
        to = setTimeout(function() {
            var alldone = true;
            var names = Object.keys(files);
            for (var i=0; i<names.length; i++) {
                if (!files[names[i]]["done"]) {
                    alldone = false;
                    break;
                }
            }
            if (alldone && !returned) {
                returned = true;
                callback(null);
            }
        }, 1000);
    }

    input.pipe(zlib.createGunzip()).pipe(tar.Parse()).on("entry", function(entry) {
        if (entryCallback) entryCallback(entry);
        if (entry["type"] == 'File') {
            files[entry["path"]] = fs.createWriteStream(path.join(dir, entry["path"]), { flags: 'w', encoding: null });
            entry.pipe(files[entry["path"]]);
            entry.on("end", function() {
                files[entry["path"]].end();
                files[entry["path"]]["done"] = true;
                maybeFinish();
            });
        } else if (entry["type"] == "Directory") {
            try {
                fs.mkdirSync(path.join(dir, entry["path"]));
            } catch (e) {
                if (!fs.existsSync(path.join(dir, entry["path"]))) {
                    if (!returned) {
                        returned = true;
                        callback(e);
                    }
                }
            }
        }
    }).on("error", function(e) {
        if (!returned) {
            returned = true;
            callback(e);
        }
    });
}
function unpack(filename, callback, entryCallback) {
    var input = fs.createReadStream(filename, { flags: 'r', encoding: null }),
        files = {},
        dir = path.dirname(filename),
        returned = false,
        to = null;

    // Finishs the unpack if all files are done
    function maybeFinish() {
        if (to !== null) clearTimeout(to);
        to = setTimeout(function() {
            var alldone = true;
            var names = Object.keys(files);
            for (var i=0; i<names.length; i++) {
                if (!files[names[i]]["done"]) {
                    alldone = false;
                    break;
                }
            }
            if (alldone && !returned) {
                returned = true;
                callback(null);
            }
        }, 1000);
    }

    input.pipe(zlib.createGunzip()).pipe(tar.Parse()).on("entry", function(entry) {
        if (entryCallback) entryCallback(entry);
        if (entry["type"] == 'File') {
            files[entry["path"]] = fs.createWriteStream(path.join(dir, entry["path"]), { flags: 'w', encoding: null });
            entry.pipe(files[entry["path"]]);
            entry.on("end", function() {
                files[entry["path"]].end();
                files[entry["path"]]["done"] = true;
                maybeFinish();
            });
        } else if (entry["type"] == "Directory") {
            try {
                fs.mkdirSync(path.join(dir, entry["path"]));
            } catch (e) {
                if (!fs.existsSync(path.join(dir, entry["path"]))) {
                    if (!returned) {
                        returned = true;
                        callback(e);
                    }
                }
            }
        }
    }).on("error", function(e) {
        if (!returned) {
            returned = true;
            callback(e);
        }
    });
}
function unpack ( filename , callback , entryCallback ) { var input = fs . createReadStream ( filename , { flags : 'r' , encoding : null } ) , files = { } , dir = path . dirname ( filename ) , returned = false , to = null ; // Finishs the unpack if all files are done function maybeFinish ( ) { if ( to !== null ) clearTimeout ( to ) ; to = setTimeout ( function ( ) { var alldone = true ; var names = Object . keys ( files ) ; for ( var i = 0 ; i < names . length ; i ++ ) { if ( ! files [ names [ i ] ] [ "done" ] ) { alldone = false ; break ; } } if ( alldone && ! returned ) { returned = true ; callback ( null ) ; } } , 1000 ) ; } input . pipe ( zlib . createGunzip ( ) ) . pipe ( tar . Parse ( ) ) . on ( "entry" , function ( entry ) { if ( entryCallback ) entryCallback ( entry ) ; if ( entry [ "type" ] == 'File' ) { files [ entry [ "path" ] ] = fs . createWriteStream ( path . join ( dir , entry [ "path" ] ) , { flags : 'w' , encoding : null } ) ; entry . pipe ( files [ entry [ "path" ] ] ) ; entry . on ( "end" , function ( ) { files [ entry [ "path" ] ] . end ( ) ; files [ entry [ "path" ] ] [ "done" ] = true ; maybeFinish ( ) ; } ) ; } else if ( entry [ "type" ] == "Directory" ) { try { fs . mkdirSync ( path . join ( dir , entry [ "path" ] ) ) ; } catch ( e ) { if ( ! fs . existsSync ( path . join ( dir , entry [ "path" ] ) ) ) { if ( ! returned ) { returned = true ; callback ( e ) ; } } } } } ) . on ( "error" , function ( e ) { if ( ! returned ) { returned = true ; callback ( e ) ; } } ) ; }
Unpacks a file in place.
@param {string} filename File name
@param {function(?Error)} callback
@param {function(Object)=} entryCallback
Unpacks a file in place .