node.js - 错误:curl 文件时使用 Gunzip 进行的标头检查不正确
问题描述
在 shell 中使用命令curl https://nodejs.org/dist/v0.1.100/node-v0.1.100.tar.gz | node stream-pipe.js
检索文件node-v0.1.100.tar.gz
并解压缩-修改-压缩它,当我尝试解压缩时zlib.createGunzip()
出现错误:
Error: incorrect header check
at Zlib.zlibOnError [as onerror] (node:zlib:190:17)
Emitted 'error' event on Gunzip instance at:
at Gunzip.onerror (node:internal/streams/readable:769:14)
at Gunzip.emit (node:events:369:20)
at emitErrorNT (node:internal/streams/destroy:188:8)
at emitErrorCloseNT (node:internal/streams/destroy:153:3)
at processTicksAndRejections (node:internal/process/task_queues:81:21) {
errno: -3,
code: 'Z_DATA_ERROR'
}
代码:
const zlib=require('zlib')
const map=require('tar-map-stream')
const decompress=zlib.createGunzip()
const whoami=process.env.USER || process.env.USERNAME
const convert=map((header)=>{
header.uname=whoami
header.mtime=new Date()
header.name=header.name.replace('node-v0.1.100','v0.1.100')
return header
})
const compress=zlib.createGzip()
process.stdin.pipe(decompress).pipe(convert).pipe(compress).pipe(process.stdout)
如果我尝试在我的本地文件夹中获取文件,它运行良好:
const zlib=require('zlib')
const map=require('tar-map-stream')
const fs=require('fs')
const decompress=zlib.createGunzip()
const whoami='amico_delle_tette'
const convert=map((header)=>{
header.uname=whoami
header.mtime=new Date()
header.name=header.name.replace('node-v0.1.100','v0.1.100')
return header
})
const compress=zlib.createGzip()
const stream=fs.createReadStream('node-v0.1.100.tar.gz')
const out=fs.createWriteStream('q.tar.gz')
stream.pipe(decompress).pipe(convert).pipe(compress).pipe(out)
什么原因?
解决方案
推荐阅读
- css - 我希望菜单在按下按钮时从右侧滑入反应
- c# - 为什么在 .net5 上运行的 Function App 报告缺少/空的服务总线连接字符串?
- c# - 如何制作一个控制windows音量的TrackBar C#
- python-3.x - Python Pandas 从源(单列)获取数据以纠正表格格式
- .net - 如何在 .net 网站项目中使用 2 个不同的包版本
- java - 如何在对应java语法的python中实现相同的for循环
- sql - SQL查找使用同一帐户的多个用户
- python - 训练 keras LSTM 模型时“无法将 NumPy 数组转换为张量”
- python - AttributeError:如果 DataFrame 被腌制为根,则无法获取属性“new_block”
- java - 无法在 java servlet 和 mysql 连接中保存记录