node.js压缩和解压缩
2024-09-27 11:28:24
推荐一个极其简单、及其好用的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
最新文章
- PHP中多线程处理
- Hibernate中使用Criteria查询
- 一款全兼容的播放器 videojs
- 分析App应用市场, App应用有哪些类型
- 在SQLSERVER中快速有条件删除海量数据技巧推荐
- 设计模式之美:Observer(观察者)
- 【Linux命令与工具】系统资源查看——free、uname、dmesg以及netstat
- ThreadPool for Delphi
- spring-quartz普通任务与可传参任务
- 配置NFS服务器
- [翻译]初识SQL Server 2005 Reporting Services Part 4
- apicloud教程
- java基础之类与对象2
- 转://oracle 11G+ASM for Linux手工建库
- 单节点etcd配置
- 分布式监控系统Zabbix--完整安装记录-批量添加主机和自动发现端口
- Vivado HLS初识---阅读《vivado design suite tutorial-high-level synthesis》(4)
- Chrome 不能访问tensorboard解决
- IE 8 下sharepoint 2013 难看的字体的解决方案
- climbing-stairs-动态规划,爬楼梯的路径数
热门文章
- Spring Boot多数据源
- Wormholes 虫洞 BZOJ 1715 spfa判断负环
- 配置YOLO2(ubuntu16.04+cuda8.0+opencv3.1.0)
- Qt 学习之路 2(43):QStringListModel
- gevent 传参, 中文编码
- python学习之路---day05
- 网站安装 https 证书
- bzoj3262 陌上花开 cdq分治(入门)
- 微信小程序 修改(自定义) 单选/复选按钮样式 checkbox/radio样式自定义
- Oracle KEEP的用法