Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import * as lzma from "lzma-native";
import * as fs from "fs";
const compressor = lzma.createCompressor();
const input = fs.createReadStream("tsconfig.json");
const output = fs.createWriteStream("tsconfig.json.xz");
input.pipe(compressor).pipe(output);
lzma.compress("Banana", undefined, result => {
console.log(result); //
});
lzma.compress("Bananas", 6, result => {
lzma.decompress(result, undefined, decompressedResult => {
console.log(decompressedResult.toString() === "Bananas");
});
});
lzma.LZMA().compress("Bananas", 4, result => {
function xz(file) {
const outfile = `${file}.xz`;
debug(`#xz() compressing ${file} into ${outfile}.`);
const compressor = lzma.createCompressor();
const input = fs.createReadStream(file);
const output = fs.createWriteStream(outfile);
let beforeSizeInMegabytes;
let afterSizeInMegabytes;
return fs.promises.stat(file)
.then(stats => {
beforeSizeInMegabytes = stats.size / 1000000.0;
debug(`#xz() ${file} is ${beforeSizeInMegabytes}MB`);
// start the compresion
const streams = input.pipe(compressor).pipe(output);
return streamToPromise(streams);
})
.then(() => util.statp(outfile))
compress(appPath) {
const basePath = path.dirname(appPath);
const appDir = path.basename(appPath);
const name = path.basename(appPath).replace(APP_NAME, `${APP_NAME}-${APP_VERSION}`);
const filename = `${name}.tar.xz`;
cp.execSync(`mkdir -p ${DIST_PATH}`, { stdio: 'inherit' });
console.log(`\nGenerating ${filename}...`);
tar
.c({ sync: true, cwd: basePath }, [appDir])
.pipe(lzma.createCompressor())
.pipe(fs.createWriteStream(path.join(DIST_PATH, filename)))
.on('finish', () => {
console.log(` ${filename} ready`);
});
},
return new Promise((ok, fail) => {
mkdirp.sync(path.dirname(file))
let packer = tar.Pack({noProprietary: true}).on('error', fail).on('end', ok)
fstream.Reader({path: dir, type: 'Directory'}).on('error', fail)
.pipe(packer)
.pipe(lzma.createCompressor().on('error', fail))
.pipe(fs.createWriteStream(file).on('error', fail))
})
}