mirror of
https://github.com/ershisan99/go-npm.git
synced 2026-01-24 21:02:12 +00:00
ADD unzip support
This commit is contained in:
@@ -10,6 +10,8 @@ function getStrategy({ url }) {
|
||||
|
||||
if (url.endsWith('.tar.gz')) {
|
||||
return require('../assets/untar');
|
||||
} else if (url.endsWith('.zip')) {
|
||||
return require('../assets/unzip');
|
||||
} else {
|
||||
return require('../assets/move');
|
||||
}
|
||||
|
||||
@@ -14,9 +14,6 @@ function untar({ opts, req, onSuccess, onError }) {
|
||||
|
||||
ungz.on('error', onError);
|
||||
untar.on('error', onError);
|
||||
|
||||
// First we will Un-GZip, then we will untar. So once untar is completed,
|
||||
// binary is downloaded into `binPath`. Verify the binary and call it good
|
||||
untar.on('end', onSuccess);
|
||||
|
||||
req.pipe(ungz).pipe(untar);
|
||||
|
||||
19
src/assets/unzip.js
Normal file
19
src/assets/unzip.js
Normal file
@@ -0,0 +1,19 @@
|
||||
const unzipper = require('unzipper');
|
||||
|
||||
/**
|
||||
* Unzip strategy for resources using `.zip`.
|
||||
*
|
||||
* Once unzip is completed, binary is downloaded into `binPath`.
|
||||
* Verify the binary and call it good.
|
||||
*/
|
||||
function unzip({ opts, req, onSuccess, onError }) {
|
||||
|
||||
const unzip = unzipper.Extract({ path: opts.binPath });
|
||||
|
||||
unzip.on('error', onError);
|
||||
unzip.on('close', onSuccess);
|
||||
|
||||
req.pipe(unzip);
|
||||
}
|
||||
|
||||
module.exports = unzip;
|
||||
Reference in New Issue
Block a user