[Node.js] Gzip + crypto in stream
2024-10-21 06:40:23
We can using gzip and crypto with stream:
const fs = require('fs')
const zlib = require('zlib')
const file = process.argv[2];
const crypto = require('crypto');
const {Transform} = require('stream'); const progress = new Transform({
transform(chunk, encoding, callback) {
process.stdout.write('.')
callback(null, chunk)
}
}); //crypto + gzip
fs.createReadStream(file)
.pipe(zlib.createGzip())
.pipe(crypto.createCipher('aes192', 'a_secret'))
.pipe(progress)
//.on('data', () => process.stdout.write('.')) // loading / processing
.pipe(fs.createWriteStream(file + '.zz'))
.on('finish', () => console.log('DONE'));
Also unzip it:
// uncrypto + unzip
fs.createReadStream(file)
.pipe(crypto.createCipher('aes192', 'a_secret'))
.pipe(zlib.createGunzip())
.pipe(progress)
.pipe(fs.createWriteStream(file.slice(0, -3)))
.on('finish', () => console.log('DONE'))
最新文章
- MahApps.Metro使用
- [译]Thinking in React
- AE+C# 版本更新问题 命名空间“ESRI”中不存在类型或命名空间名称“Arcgis”(是缺少程序集引用吗?)
- Unity 游戏存档 PlayerPrefs类的用法
- Backbone☞View中的events...click事件失效
- zookeeper安装及部署
- Python变量/运算符/函数/模块/string
- placeholder的兼容性探索之路
- 使用JS制作一个鼠标可拖的DIV(三)——移动带图片DIV
- 【HDOJ】2388 Playground Hideout
- apache开源项目--PDFBox
- Central Europe Regional Contest 2012 Problem I: The Dragon and the Knights
- C++程序设计实践指导1.5求两个整数集合并集改写要求实现
- win32用GDI+加载png图片作为背景图
- 【C语言】判断三角形类型
- 修改Gradle 和Maven本地仓库的位置 方法
- SElinux用户管理操作
- SpringBoot之旅第五篇-数据访问
- thinkphp5.0引入类
- Gym 101775A - Chat Group - [简单数学题][2017 EC-Final Problem A]