How to use tar

Comprehensive tar code examples:

How to use tar.default:

3
4
5
6
7
8
9
10
const tslib_1 = require("tslib");
const utils_fs_1 = require("@ionic/utils-fs");
const tar_1 = tslib_1.__importDefault(require("tar"));
async function extractTemplate(src, dir) {
    await utils_fs_1.mkdirp(dir);
    await tar_1.default.extract({ file: src, cwd: dir });
}
exports.extractTemplate = extractTemplate;

How to use tar.pack:

105
106
107
108
109
110
111
112
113
114
  .then(injectIntegrity)
  .then(() => console.log('done'));
//   return new Promise((resolve, reject) => {
//     console.log(recursiveFileList());
//     resolve();
//     // const pack = tar.pack(); // pack is a streams2 stream
//     // dirInfo.
//     // // add a file called my-test.txt with the content "Hello World!"
//     // pack.entry({ name: 'my-test.txt' }, 'Hello World!');
//     // // add a file called my-stream-test.txt from a stream

How to use tar.c:

596
597
598
599
600
601
602
603
604
605
606
607
}




async function zip_release() {
    let releaseDir = g_releaseObject.staging.folder
    await tar.c(
        {
          gzip: true,
          file: releaseDir + '.tgz'
        },

How to use tar.t:

50
51
52
53
54
55
56
57
58
59
const bundled = new Set()
let totalEntries = 0
let totalEntrySize = 0

// reads contents of tarball
const stream = tar.t({
  onentry (entry) {
    totalEntries++
    totalEntrySize += entry.size
    const p = entry.path

How to use tar.Extract:

88
89
90
91
92
93
94
95
96
97
}

debug('reading...', config.node.dest);
input = fs.createReadStream(config.node.dest);
ungzip = zlib.createGunzip();
extractor = tar.Extract({
  path: config.cache
});

extractor.on('end', function() {

How to use tar.create:

130
131
132
133
134
135
136
137
138
139
140


BuildHelper.CompressBuild = function(BuildId, OutputFolder) {
    const BuildFolder = this.GetBuildFolder(BuildId)
    const OutputFile = Path.join(OutputFolder, FS.readJSONSync(`${BuildFolder}/package.info.json`).Id) + ".twr"
    TypeWriter.Logger.Debug(`Outputting to ${OutputFile} in ${BuildFolder}`)
    Tar.create(
        {
            file: OutputFile,
            cwd: BuildFolder,
            sync: true,

How to use tar.Parse:

232
233
234
235
236
237
238
239
240
    return setResult(err)
    //return closeReadStream(rstr)
  }
}

const tarParser = new tar.Parse()
const processEntry = entry => {
  /* istanbul ignore if */
  if (entry.ignore || entry.meta) return entry.resume()

How to use tar.x:

85
86
87
88
89
90
91
92
93
94
  await decompress(artifactPath, CSFLE_DIRECTORY);
} else {
  // For .tar files, `decompress` is buggy, so we use `tar` instead
  await promisify(pipeline)(
    createReadStream(artifactPath),
    tar.x({
      C: CSFLE_DIRECTORY,
    })
  );
}

How to use tar.extract:

29
30
31
32
33
34
35
36
37
38
39
40
    process.exit(0);
  }


  await downloadIfNeeded();
  console.log('extracting...');
  await tar.extract({ file: finalFile, onwarn: process.emitWarning });
}


async function downloadIfNeeded() {
  if (fs.statSync(finalFile, { throwIfNoEntry: false })) {