[Node.js] Gzip + crypto in stream
2023-09-14 09:00:49 时间
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'))
相关文章
- 彻底理解js中this
- 【nodejs原理&源码赏析(7)】【译】Node.js中的事件循环,定时器和process.nextTick
- Node.js文件操作二
- [Tools] Create a Simple CLI Tool in Node.js with CAC
- [Node.js] Write or Append to a File in Node.js with fs.writeFile and fs.writeFileSync
- [Node.js] Take Screenshots of Multiple Dimensions for Responsive Sites using Nightmare
- [Node.js] Use "prestart" in scripts
- [Whole Web, Node.js, PM2] Configuring PM2 for Node applications
- [Node.js] Level 6. Socket.io
- Node.js 中运行定时任务
- node webkit(nw.js) 设置自动更新
- Node.js刷新session过期时间
- [Node.js] Fetch csv data and parse
- [Custom CLI] Develop and Publish a Node.js CLI from Scratch
- [Tools] Batch Create Markdown Files from a Template with Node.js and Mustache
- [Node.js] Trigger a File Download in Express
- [Node.js] Read a File in Node.js with fs.readFile and fs.readFileSync
- [Node.js] Create a model to persist data in a Node.js LoopBack API
- [Node.js] Creating JWTs (JSON Web Tokens) in Node
- How does framework require TechnicalInfo.js
- 如何从ngrx-store-devtools.js里找到actions的触发源头
- Atitit node.js自定义模块化 Function walkFileTree() exports.walkFileTree =walkFileTree 引用 Files=require
- paip.最好的脚本语言node js 环境搭建连接mysql
- Node.js: node-redis.js客户端
- Node.js学习笔记(二)——Node.js模块化、文件读写、环境变量
- Node.js学习笔记——接口
- Node.js学习笔记——mongoDB