Created
August 20, 2021 14:50
-
-
Save bytemain/ce34c0f2d0f46b34b22f5ccb810a781d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const fs = require("fs"); | |
| const zipdata = fs.createReadStream("1.zip"); | |
| const { zip, tar } = require("compressing"); | |
| async function getTarReadStream(download) { | |
| return new Promise((resolve, reject) => { | |
| function onEntry(header, stream, next) { | |
| if (header.type === "file" && header.name.endsWith(".tar")) { | |
| resolve(stream); | |
| return; | |
| } | |
| next(); | |
| } | |
| new zip.UncompressStream({ source: download }) | |
| .on("error", (e) => { | |
| console.log("e,", e); | |
| reject(new Error(`解压加签包失败:${e.name}: ${e.message}`)); | |
| }) | |
| .on("finish", () => { | |
| reject(new Error("下载的加签包中没有找到 tar 包")); | |
| }) | |
| .on("entry", onEntry); | |
| }); | |
| } | |
| (async () => { | |
| const tarStream = await getTarReadStream(zipdata); | |
| const tarExtractStream = new tar.UncompressStream({ source: tarStream }) | |
| .on("error", (e) => { | |
| console.log(e); | |
| }) | |
| .on("finish", () => { | |
| console.log("finish"); | |
| }) | |
| .on("entry", async (header, _stream, next) => { | |
| console.log(`🚀 ~ file: 1.js ~ line 37 ~ .on ~ header`, header); | |
| next(); | |
| }); | |
| console.log(`🚀 ~ file: 1.js ~ line 30 ~ tarExtractStream`, tarExtractStream); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment