Created
March 24, 2022 23:36
-
-
Save lucaswiman/9bd01ae0af676de511c7184a3dc0b003 to your computer and use it in GitHub Desktop.
js untar in memory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const tar = require("tar"); | |
exports.unTar = (tarballStream) => { | |
const results = {}; | |
return new Promise((resolve, reject) => { | |
const parser = tarballStream.pipe(new tar.Parse()); | |
parser.on( | |
"entry", async (entry) => { | |
const chunks = [] | |
for await (let chunk of entry) { | |
chunks.push(chunk); | |
} | |
results[entry.path] = Buffer.concat(chunks); | |
console.log(entry.path); | |
} | |
).once("end", () => { | |
resolve(results); | |
}).on("error", (err) => { | |
reject(err); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment