ms/packages/common/src/tgz.ts
MiaoWoo ca79161505 refactor: rename scope to @ccms
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-05-03 00:14:47 +08:00

24 lines
871 B
TypeScript

import '@ccms/nashorn'
let Files = Java.type("java.nio.file.Files");
let Paths = Java.type("java.nio.file.Paths");
let StandardCopyOption = Java.type("java.nio.file.StandardCopyOption");
let TarInputStream = Java.type("org.kamranzafar.jtar.TarInputStream");
let GZIPInputStream = Java.type("java.util.zip.GZIPInputStream");
let BufferedInputStream = Java.type("java.io.BufferedInputStream");
function decompression(input: any, target: string) {
let tis = new TarInputStream(new BufferedInputStream(new GZIPInputStream(input)));
let entry: any;
while ((entry = tis.getNextEntry()) != null) {
let targetPath = Paths.get(target + "/" + entry.getName().substring("package/".length));
targetPath.toFile().getParentFile().mkdirs();
Files.copy(tis, targetPath, StandardCopyOption.REPLACE_EXISTING);
}
}
export = {
decompression
}