ADD unit tests, split and refactor source code

This commit is contained in:
RecuencoJones
2019-03-25 20:38:29 +01:00
parent 6eaf5fc9af
commit 8257010937
18 changed files with 782 additions and 392 deletions

25
src/assets/untar.js Normal file
View 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;