mirror of
https://github.com/ershisan99/go-npm.git
synced 2025-12-24 12:33:41 +00:00
ADD unit tests, split and refactor source code
This commit is contained in:
25
src/assets/untar.js
Normal file
25
src/assets/untar.js
Normal file
@@ -0,0 +1,25 @@
|
||||
const tar = require('tar');
|
||||
const zlib = require('zlib');
|
||||
|
||||
/**
|
||||
* Unzip strategy for resources using `.tar.gz`.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
function untar({ opts, req, onSuccess, onError }) {
|
||||
|
||||
const ungz = zlib.createGunzip();
|
||||
const untar = tar.Extract({ path: opts.binPath });
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
module.exports = untar;
|
||||
Reference in New Issue
Block a user