Last active
March 31, 2023 09:24
-
-
Save xhsdnn/91d962400afb00eb700a88f60f57f119 to your computer and use it in GitHub Desktop.
This file contains 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 { createReadStream, createWriteStream } = require('fs'); | |
const tar = require(tar); | |
const dest = process.cwd(); | |
// A: remote download | |
// A1: use lib | |
let res = await axios.get(url, { | |
responseType: 'stream' | |
}); | |
let writer1 = createWriteStream(dest, { | |
encoding: 'utf8' | |
}); | |
res.data.pipe(writer1); | |
// A2: native | |
/* https or */http.get(url, (response) => { | |
response.pipe(writer1); | |
}); | |
// A3: event | |
writer1.on('finish', () => { | |
// resolve(); | |
}); | |
writer1.on('error', (e) => { | |
// reject(e); | |
}); | |
// B: unpack | |
let writer2 = tar.x({ | |
strict: 1, | |
C: dest | |
}); | |
// B1: use lib from remote | |
let res = await axios.get(url, { | |
responseType: 'stream' | |
}); | |
res.data.pipe(writer2); | |
// B2: use lib from local | |
createReadStream(localSource).pipe(writer2); | |
// B3: similar to A3 | |
// C: pack | |
// use lib similar to B —— use "tar" | |
// D: A and B can be mixed simple |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment