Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public async extract(): Promise {
log.verbose('Lfw', 'extract()')
const EXTRACTED_MARK_FILE = path.join(this.directory, 'EXTRACTED')
if (fs.existsSync(EXTRACTED_MARK_FILE)) {
log.silly('Lfw', 'extract() already extracted')
return
}
await tar.x({
file: this.downloadFile,
strip: 1,
cwd: this.directory,
})
fs.closeSync(fs.openSync(EXTRACTED_MARK_FILE, 'w')) // touch the file
}
for (let version in latestMajors) {
const filePath = path.resolve(__dirname, '../public', `${version}.tar`);
const directoryTmp = path.resolve(__dirname, '../public', `${version}-tmp`);
const directory = path.resolve(__dirname, '../public', `${version}`);
mkdirp.sync(directoryTmp);
mkdirp.sync(directory);
await downloadFile({
latestMajors,
version,
filePath,
});
tar.x({
file: filePath,
cwd: directoryTmp,
sync: true,
strip: 1,
});
// eventstream 3 has a security issue and was removed from the registry
if (Number(version.replace('v', '')) < 5) {
patchEventstream(path.resolve(directoryTmp, 'package.json'));
}
childProcess.execSync('yarn install', {
cwd: directoryTmp,
});
childProcess.execSync(majors[version].buildCommand, {
response.on('data', chunk => bar.tick(chunk.length))
.pipe(outputFile)
.on('close', async () => {
const zipFile = new zip(tempFileName);
zipFile.extractAllTo(destPath, true /* overwrite */);
await unlink(tempFileName);
if (callback !== undefined) {
callback();
}
});
} else if (uri.endsWith('.tar.gz')) {
response.on('data', chunk => bar.tick(chunk.length))
.pipe(tar.x({C: destPath, strict: true}))
.on('close', () => {
if (callback !== undefined) {
callback();
}
});
} else {
throw new Error(`Unsupported packed resource: ${uri}`);
}
});
request.end();
extract(filename: string, dest: string) {
console.log(`extract ${filename}...`)
return tar.x({
file: filename,
C: dest
})
}
return new Promise((resolve, reject) => {
if (!fs.existsSync(archivePath)) {
reject(new Error(`The archive was not found at ${archivePath}.`));
return;
}
if (!fs.existsSync(targetPath)) {
mkdirp.sync(targetPath);
}
const gunzip = zlib.createGunzip({ finishFlush: zlib.Z_SYNC_FLUSH, flush: zlib.Z_SYNC_FLUSH });
console.log(`Decompressing the archive to ${targetPath}.`);
const untar = tar.x({ cwd: targetPath });
fs.createReadStream(archivePath).pipe(gunzip).pipe(untar)
.on('error', e => reject(e))
.on('end', () => resolve());
});
}
sha256,
})
)
}
})
if (!this.spec.extract) {
const targetExecutable = join(tmpPath, ...this.targetSubpath)
response.data.pipe(createWriteStream(targetExecutable))
response.data.on("end", () => resolve())
} else {
const format = this.spec.extract.format
let extractor: Writable
if (format === "tar") {
extractor = tar.x({
C: tmpPath,
strict: true,
})
extractor.on("end", () => resolve())
} else if (format === "zip") {
extractor = Extract({ path: tmpPath })
extractor.on("close", () => resolve())
} else {
reject(
new ParameterError(`Invalid archive format: ${format}`, {
name: this.name,
spec: this.spec,
})
)
return
}
async function decompressArchive(file, targetDir) {
return tar.x({
file,
cwd: targetDir,
});
}
.then(() => {
tar.x(
{
file: destTemp,
cwd: c.paths.workspace.dir
}
).then(() => {
removeFilesSync([destTemp]);
if (fs.existsSync(ts)) {
copyFileSync(ts, path.join(c.paths.workspace.dir, c.files.project.package.name, 'timestamp'));
}
logSuccess(`Files succesfully extracted into ${c.paths.workspace.dir}`);
resolve();
})
.catch(e => reject(e));
}).catch((e) => {
reject(e);
return new Promise(function(resolve, reject) {
var untar = tar
.x({ cwd: path })
.on("error", function(error) {
reject("Error extracting " + url + " - " + error);
})
.on("end", function() {
var successMessage = "Successfully downloaded and processed " + url;
if (verify) {
verifyContents(verify)
.then(function() {
resolve(successMessage);
})
.catch(reject);
} else {
resolve(successMessage);
}
function extractTar(filename, packageDirectory, cb) {
const o_fs = require('fs-extra');
const tar = require('tar');
o_fs.createReadStream(filename).pipe(
tar.x({
strip: 1,
C: packageDirectory
}).on('end', function () {
cb();
})
);
}