如何用nodejs压缩文件,生成tar包

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何用nodejs压缩文件,生成tar包相关的知识,希望对你有一定的参考价值。

参考技术A [js压缩]uglifyjs source.js -mc -o target.min.js
压缩angular.js例压缩局部变量名掉用局部变量空白符等压缩比例接近80%效率错
[user_00@localhost ~]$ uglifyjs angular.js -mc -o angular.min.js
WARN: Dropping unused function isBoolean [angular.js:416,9]
WARN: Dropping unused function makeMap [angular.js:446,9]
WARN: Dropping unused function size [angular.js:488,9]
WARN: Dropping unused function isLeafNode [angular.js:523,9]
WARN: Dropping unused function argument boundTranscludeFn [angular.js:4682,27]
WARN: Dropping unused function argument rootElement [angular.js:4681,16]
WARN: Dropping unused function argument nodeList [angular.js:4680,17]
WARN: Dropping unused function argument scope [angular.js:4679,22]
WARN: Dropping unused function nodesetLinkingFn [angular.js:4678,9]
WARN: Dropping unused function argument boundTranscludeFn [angular.js:4690,27]
WARN: Dropping unused function argument rootElement [angular.js:4689,16]
WARN: Dropping unused function argument node [angular.js:4688,13]
WARN: Dropping unused function argument scope [angular.js:4687,22]
WARN: Dropping unused function argument nodesetLinkingFn [angular.js:4686,25]
WARN: Dropping unused function directiveLinkingFn [angular.js:4685,9]
WARN: Dropping unused function stripHash [angular.js:5009,9]
WARN: Dropping unused variable NG_SWITCH [angular.js:13857,4]
WARN: Dropping unused variable fns [angular.js:1536,8]
WARN: Dropping unused variable events [angular.js:1536,13]
WARN: Dropping unused function wrongMode [angular.js:3879,13]
WARN: Dropping unused function argument cause [angular.js:4799,31]
WARN: Dropping unused function argument exception [angular.js:4799,20]
WARN: Dropping unused function argument args [angular.js:8165,28]
WARN: Dropping unused function argument args [angular.js:8231,33]
WARN: Dropping unused function argument names [angular.js:9018,32]
WARN: Dropping unused function argument name [angular.js:9030,40]
WARN: Dropping unused variable value [angular.js:9230,14]
WARN: Dropping unused function argument value [angular.js:12475,36]
[user_00@localhost ~]$ ls -lh angular.*
-rw-rw-r-- 1 user_00 user_00 479K Apr 5 01:53 angular.js
-rw-rw-r-- 1 user_00 user_00 79K May 4 16:09 angular.min.js
现我test.tar文件通tar -xvf test.tar 解压缩文件夹test现我想解压缩文件夹名称直接改123,命令哪位帮忙答本回答被提问者和网友采纳

java 如何用zlib解压缩tar.gz文件

参考技术A public static void makeZip(List<File> fileList,String zipPath,boolean isDelete)
byte[] buf = new byte[1024];
try
// Create the ZIP file
File zipFile = new File(zipPath);
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipFile));
// Compress the files
for (int i = 0; i < fileList.size(); i++)
FileInputStream in = new FileInputStream(fileList.get(i));
// Add ZIP entry to output stream.
out.putNextEntry(new ZipEntry(fileList.get(i).getName()));
// Transfer bytes from the file to the ZIP file
int len;
while ( (len = in.read(buf)) > 0)
out.write(buf, 0, len);

// Complete the entry
out.closeEntry();
in.close();

// Complete the ZIP file
out.close();
System.out.println("压缩完成.");

//把旧的文件删除
if(isDelete == true)
for (int i = 0; i < fileList.size(); i++)
File oldFile = fileList.get(i);
oldFile.delete();



catch (IOException e)
e.printStackTrace();


public static void main(String[] args)
File in1=new File("D:\\a.txt");
File in2=new File("D:\\b.txt");
File[] file=new File[]in1,in2;
File zip=new File("D:\\ab.zip");
IDMZip mgr=new IDMZip();
mgr.ZipFiles(file, zip);


这个方法不管你是在windows下还是在linux下,都能正常执行。追问

谢谢,但是我是要解压这样20140718_185819.data.tar.gz 不是zip的

追答

你可以试试。还有这个方法。都是我项目里曾经用到过的。都是可用的。
public static List unZip(String path) throws FileNotFoundException,
IOException
path = path.replaceAll("\\\\","/");
String zipPath = path.substring(0,path.lastIndexOf("/")+1);
List xmlFileNameList = new ArrayList();
byte[] data = new byte[1024*2];
FileInputStream fis = new FileInputStream(path);
ZipInputStream zis = new ZipInputStream(fis);
ZipEntry entry = null;
while((entry = zis.getNextEntry())!= null)
if(entry.isDirectory())
File file = new File(zipPath+entry.getName());
file.mkdirs();
continue;

本回答被提问者采纳

以上是关于如何用nodejs压缩文件,生成tar包的主要内容,如果未能解决你的问题,请参考以下文章

java 如何用zlib解压缩tar.gz文件

如何用tar压缩文件夹到指定目录

linux 如何用 unzip解压一个压缩包中的一个文件? tar可以

如何用SAS读取压缩包内的文件或是自动解压文件

如何用dos命令将档压缩成ZIP?

python tar.gz怎么安装