推荐一个极其简单、及其好用的node.js的压缩和解压缩类库  compressing

支持格式: tar、gzip、tgz、zip

以zip为例,tar,tgz和gzip与zip相同。

压缩文件:

const compressing = require('compressing');
compressing.zip.compressFile('logs/info-2018-06-07.log', 'logs/test.zip').then(() => {}).catch(() => {}); //或者
await compressing.zip.compressFile('logs/info-2018-06-07.log', 'logs/test.zip')

压缩文件夹:

const compressing = require('compressing');
compressing.zip.compressDir('logs', 'test3.zip').then(()=>{}).catch(()=>{}); //或者
await compressing.zip.compressDir('logs', 'test3.zip')

使用Stream压缩多个文件(非常强大)

const fs=require('fs');
const compressing = require('compressing');
const zipStream = new compressing.zip.Stream();
zipStream.addEntry('./logs/error-2018-06-07.log')
zipStream.addEntry('./logs/info-2018-06-07.log') const destStream = fs.createWriteStream('test4.zip'); const pipe = require('multipipe');
pipe(zipStream, destStream, (err) => {
console.log(err);
})

Stream可以是dir、file、buffer、stream

// dir
zipStream.addEntry('dir/path/to/compress'); // file
zipStream.addEntry('file/path/to/compress'); // buffer
zipStream.addEntry(buffer); // stream
zipStream.addEntry(stream);

解压缩:

const compressing = require('compressing');
compressing.zip.uncompress('test3.zip', 'test3').then(() => {}).catch(() => {});
//或者
await compressing.zip.uncompress('test3.zip', 'test3') //如果要解压到当前目录换成 './'

更多内容:

https://github.com/node-modules/compressing

https://www.npmjs.com/package/compressing

最新文章

  1. PHP中多线程处理
  2. Hibernate中使用Criteria查询
  3. 一款全兼容的播放器 videojs
  4. 分析App应用市场, App应用有哪些类型
  5. 在SQLSERVER中快速有条件删除海量数据技巧推荐
  6. 设计模式之美:Observer(观察者)
  7. 【Linux命令与工具】系统资源查看——free、uname、dmesg以及netstat
  8. ThreadPool for Delphi
  9. spring-quartz普通任务与可传参任务
  10. 配置NFS服务器
  11. [翻译]初识SQL Server 2005 Reporting Services Part 4
  12. apicloud教程
  13. java基础之类与对象2
  14. 转://oracle 11G+ASM for Linux手工建库
  15. 单节点etcd配置
  16. 分布式监控系统Zabbix--完整安装记录-批量添加主机和自动发现端口
  17. Vivado HLS初识---阅读《vivado design suite tutorial-high-level synthesis》(4)
  18. Chrome 不能访问tensorboard解决
  19. IE 8 下sharepoint 2013 难看的字体的解决方案
  20. climbing-stairs-动态规划,爬楼梯的路径数

热门文章

  1. Spring Boot多数据源
  2. Wormholes 虫洞 BZOJ 1715 spfa判断负环
  3. 配置YOLO2(ubuntu16.04+cuda8.0+opencv3.1.0)
  4. Qt 学习之路 2(43):QStringListModel
  5. gevent 传参, 中文编码
  6. python学习之路---day05
  7. 网站安装 https 证书
  8. bzoj3262 陌上花开 cdq分治(入门)
  9. 微信小程序 修改(自定义) 单选/复选按钮样式 checkbox/radio样式自定义
  10. Oracle KEEP的用法