node.js - 通过 Cloud Functions 从 Cloud Storage 解压缩文件
问题描述
我的 Google Cloud Storage中有 gzip 文件,我必须检查使用Cloud Functions压缩的文件的校验和。
我开始使用此示例中的解压缩示例,但它仅适用于 ZIP 文件而非 gzip:
gcsSrcObject.createReadStream()
.pipe(unzipper.Parse())
.pipe(stream.Transform({
objectMode: true,
transform: function (entry, e, callback) {
var filePath = entry.path;
var type = entry.type;
var size = entry.size;
console.log(`Found ${type}: ${filePath}`);
console.log(`Unzipping to: ${TEMP}/${prefix}/${filePath}`)
var gcsDstObject = dstBucket.file(`${TEMP}/${prefix}/${filePath}`);
entry
.pipe(gcsDstObject.createWriteStream())
.on('error', function (err) {
console.log(`Error: ${err}`);
})
.on('finish', function () {
console.log('Complete');
callback();
});
}
}));
我还阅读了有关本机存储功能(gsutil cp)的文档,但它只允许您从本地复制 GZIP 文件。
解决方案
请记住,如果您的文件使用“Content-Encoding: gzip”存储在 GCS 中,那么您可以透明地即时解压缩它们。GCS 将此称为“转码”
推荐阅读
- azure - 我可以过滤从应用中心导出的遥测数据到应用洞察吗?
- r - R 代码在 RStudio 中工作正常,但在终端中不能正常工作 - ODBC SQL - 无法加载安全库:(libgssapi_krb5.dylib)
- android - convert_model.tflite 未编码有效的 TensorFlowLite 模型:无法打开 file_path。该模型不是有效的 Flatbuffer 文件
- python - 如何避免我的 python 代码将值四舍五入到小数点后 1 位
- amazon-web-services - 如何根据 S3 事件将文件从 s3 部署到 ec2 实例
- internet-explorer - 在 IE 中打开时在 jquery 中使用此符号 => 的语法错误
- office-js - 如何从 office.js 代码内部连接服务器
- mysql - 在 django 中获取字符编码错误错误的字符串值:'\\xF0\\x9F\\x
- c# - 作为 dotnet cli 工具启动时获取“此平台不支持 System.Data.SqlClient”
- awk - 文本处理:根据另一列值偏移一列中的日期值