How to use the tar.extract function in tar

To help you get started, we’ve selected a few tar examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github caprover / caprover / built / user / ImageMaker.js View on Github external
.then(function () {
            // If uploadedTarPath then extract into a directory
            //
            // If Repo then download.
            //
            // If captainDefinitionContent then create a directory and output to a directory
            //
            // Else THROW ERROR
            const srcTar = source.uploadedTarPathSource;
            if (srcTar) {
                // extract file to to destDirectory
                return tar
                    .extract({
                    file: srcTar.uploadedTarPath,
                    cwd: destDirectory,
                })
                    .then(function () {
                    return srcTar.gitHash;
                });
            }
            const srcRepo = source.repoInfoSource;
            if (srcRepo) {
                return GitHelper.clone(srcRepo.user, srcRepo.password, srcRepo.repo, srcRepo.branch, destDirectory).then(function () {
                    return GitHelper.getLastHash(destDirectory);
                });
            }
            const captainDefinitionContentSource = source.captainDefinitionContentSource;
            if (captainDefinitionContentSource) {
github microsoft / rushstack / apps / rush-lib / src / cli / utilities / LinkManager.ts View on Github external
// Example: "project1"
      const unscopedTempProjectName: string = Utilities.parseScopedPackageName(project.tempProjectName).name;

      // Example: "C:\MyRepo\common\temp\projects\project1
      const extractedFolder: string = path.join(this._rushConfiguration.commonTempFolder,
        RushConstants.rushTempProjectsFolderName, unscopedTempProjectName);

      // Example: "C:\MyRepo\common\temp\projects\project1.tgz"
      const tarballFile: string = path.join(this._rushConfiguration.commonTempFolder,
        RushConstants.rushTempProjectsFolderName, unscopedTempProjectName + '.tgz');

      // Example: "C:\MyRepo\common\temp\projects\project1\package.json"
      const packageJsonFilename: string = path.join(extractedFolder, 'package', 'package.json');

      Utilities.createFolderWithRetry(extractedFolder);
      tar.extract({
        cwd: extractedFolder,
        file: tarballFile,
        sync: true
      });

      // Example: "C:\MyRepo\common\temp\node_modules\@rush-temp\project1"
      const installFolderName: string = path.join(this._rushConfiguration.commonTempFolder,
        RushConstants.nodeModulesFolderName, RushConstants.rushTempNpmScope, unscopedTempProjectName);

      commonProjectPackage = Package.createVirtualTempPackage(packageJsonFilename, installFolderName);

      // remove the extracted tarball contents
      fsx.removeSync(packageJsonFilename);
      fsx.removeSync(extractedFolder);

      commonRootPackage.addChild(commonProjectPackage);
github Gottwik / Enduro / libs / theme_manager / theme_manager.js View on Github external
return new Promise(function (resolve, reject) {
				// downloads and extracts
				request(gz_link)
					.pipe(tar.extract({
						cwd: path.join(enduro.project_path, project_name),
						strip: 1,
						strict: 1,
				}))
				.on('close', function () {
					logger.loaded()
					global.enduro.project_path = path.join(enduro.project_path, project_name)
					resolve()
				})
			})
		})
github mendersoftware / gui / node_modules / fsevents / node_modules / node-pre-gyp / lib / install.js View on Github external
req.on('response', function(res) {
           // ignore redirects, needle handles these automatically.
           if (res.headers.hasOwnProperty('location') && res.headers.location !== '') {
             return;
           }
           if (res.statusCode !== 200) {
                badDownload = true;
                var err = new Error(res.statusCode + ' status code downloading tarball ' + from);
                err.statusCode = res.statusCode;
                return callback(err);
            }
            // start unzipping and untaring
            req.pipe(tar.extract({
              cwd: to,
              strip: 1,
              onentry: filter_func
            }).on('close', afterTarball).on('error', callback));
        });
    });
github prisma / prisma2 / cli / introspection / src / prompt / screens / Step60DownloadExample.tsx View on Github external
export async function extractExample(tmpPath: string, examplePath: string, outputPath: string): Promise {
  await tar.extract({
    file: tmpPath,
    cwd: outputPath,
    filter: filePath => {
      return !filePath.includes('/.github/') && RegExp(examplePath).test(filePath)
    },
    strip: examplePath.split('/').length - 1,
  })
}
github lovell / sharp / install / libvips.js View on Github external
const extractTarball = function (tarPath) {
  const vendorPath = path.join(__dirname, '..', 'vendor');
  libvips.mkdirSync(vendorPath);
  tar
    .extract({
      file: tarPath,
      cwd: vendorPath,
      strict: true
    })
    .catch(function (err) {
      if (/unexpected end of file/.test(err.message)) {
        npmLog.error('sharp', `Please delete ${tarPath} as it is not a valid tarball`);
      }
      fail(err);
    });
};
github mapbox / node-pre-gyp / lib / install.js View on Github external
function extract(to, callback) {
    var extractCount = 0;
    function filter_func(entry) {
        log.info('install','unpacking ' + entry.path);
        extractCount++;
    }

    function afterTarball(err) {
        callback(err, extractCount);
    }

    var tar = require('tar');
    return tar.extract({
        cwd: to,
        strip: 1,
        onentry: filter_func
    }).on('close', afterTarball).on('error', callback);
}
github microsoft / just / packages / just-scripts-utils / src / downloadPackage.ts View on Github external
fse.mkdirpSync(pkgPath);
  const result = spawnSync(npmCmd, ['pack', `${pkg}@${version}`, '--no-cache', ...(registry ? ['--registry', registry] : [])], {
    cwd: pkgPath
  });

  if (result.error) {
    logger.error('Error fetching package');
    logger.error(result.error);
    return null;
  }

  const files = fse.readdirSync(pkgPath);
  const pkgFile = files.find(file => file.endsWith('tgz'));

  if (pkgFile) {
    await tar.extract({
      file: path.join(pkgPath, pkgFile),
      cwd: pkgPath
    });
    return path.join(pkgPath, 'package');
  } else {
    logger.error(`Could not find downloaded tgz file ${pkgPath}`);
    return null;
  }
}