How to use the pack function from tar-fs
Find comprehensive JavaScript tar-fs.pack code examples handpicked from public code repositorys.
tar-fs.pack is a function in Node.js that packs a directory into a tar stream.
GitHub: asg017/sqlite-lines
23 24 25 26 27 28 29 30 31 32 33 34 35
function targz(files) { return new Promise((resolve, reject) => { console.log("targz files: ", files[0].name, files[0]); const tarStream = tar.pack(); for (const file of files) { tarStream.entry({ name: file.name }, file.data); }
GitHub: bbc/speculate
56 57 58 59 60 61 62 63 64 65
writeStream.emit('close'); await result; sinon.assert.calledWith(tar.pack, 'tmp', sinon.match.object); const ignore = tar.pack.getCall(0).args[1].ignore; assert.equal(ignore('SPECS'), true); assert.equal(ignore('SOURCES'), true); assert.equal(ignore('RPMS'), true); assert.equal(ignore('SRPMS'), true);
How does tar-fs.pack work?
tar-fs.pack
is a method in the tar-fs
module of Node.js that creates a new tar
stream and adds files or directories to the stream.
When files are added, tar-fs
will create a new tar
entry for each file and add the file data to the stream. If directories are added, tar-fs
will recursively add all files and subdirectories within the directory to the stream.
This method is useful for creating tar
archives of one or more files or directories in a streaming fashion.
GitHub: athombv/node-homey
1271 1272 1273 1274 1275 1276 1277 1278 1279 1280
let numFiles = 0; const tmpFile = await tmp.file(); await pipeline( tar.pack(appPath, { dereference: true, map(header) { if (header.type === 'file') numFiles += 1; },
46 47 48 49 50 51 52 53 54 55
console.log(await makeSiteResponse.text()); } // put request to upload the content console.log("Creating tarball..."); const tarStream = tar.pack(publishDir); const formData = new FormData(); formData.append('file', tarStream, siteURL); console.log("Uploading new site content...");
Ai Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14
const fs = require("fs"); const tar = require("tar-fs"); const sourceDir = "/path/to/source/directory"; const tarFilePath = "/path/to/archive.tar"; const tarStream = tar.pack(sourceDir); const writeStream = fs.createWriteStream(tarFilePath); tarStream.pipe(writeStream); writeStream.on("finish", () => { console.log(`Created archive file: ${tarFilePath}`); });
This example creates a tar archive of the sourceDir directory and saves it to the tarFilePath file. The tar.pack method returns a readable stream that can be piped to a writable stream (in this case, a file stream created using fs.createWriteStream). When the write stream finishes writing the archive to the file, a message is logged to the console.
12 13 14 15 16 17 18 19 20 21 22 23 24
let createOptions; exports.buildImage = async function (template) { const path = `../Bots/${template}`; const tarStream = tar.pack(path); docker.buildImage(tarStream, { t: ((template).toLowerCase()), }, (error, output) => {
tar-fs.extract is the most popular function in tar-fs (77 examples)