Skip to content

Instantly share code, notes, and snippets.

@lucaswiman
Created March 24, 2022 23:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucaswiman/9bd01ae0af676de511c7184a3dc0b003 to your computer and use it in GitHub Desktop.
Save lucaswiman/9bd01ae0af676de511c7184a3dc0b003 to your computer and use it in GitHub Desktop.
js untar in memory
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