11const fs = require ( 'fs' ) ;
22const request = require ( 'request' ) ;
33const tar = require ( 'tar' ) ;
4- const extract = require ( 'extract -zip' ) ;
4+ const AdmZip = require ( 'adm -zip' ) ;
55const lzma = require ( 'lzma-native' ) ;
66const system = require ( './system' ) ;
77const console = require ( './console' ) ;
@@ -28,12 +28,9 @@ function decompressXZ(file) {
2828 } ) ;
2929}
3030function decompressZip ( file ) {
31- return new Promise ( resolve => {
32- let dir = file . substring ( 0 , file . lastIndexOf ( '.' ) ) ;
33- extract ( file , { dir : `${ system . rootDir } /ffmpeg` } , e => {
34- if ( ! e ) resolve ( dir ) ;
35- } ) ;
36- } ) ;
31+ let zip = AdmZip ( file ) ;
32+ zip . extractAllTo ( `${ system . rootDir } /ffmpeg` , true ) ;
33+ return file . substring ( 0 , file . lastIndexOf ( '.' ) ) ;
3734}
3835
3936function rimraf ( dir ) {
@@ -47,16 +44,6 @@ function rimraf(dir){
4744 fs . rmdirSync ( dir ) ;
4845}
4946
50- function forceRename ( oldPath , newPath , max = 0 ) {
51- try {
52- Atomics . wait ( new Int32Array ( new SharedArrayBuffer ( 4 ) ) , 0 , 0 , max * 100 ) ;
53- fs . renameSync ( oldPath , newPath ) ;
54- } catch ( e ) {
55- if ( max < 10 ) forceRename ( oldPath , newPath , ++ max ) ;
56- else throw console . error ( 'Unable to rename FFmpeg folder' ) ;
57- }
58- }
59-
6047async function getPackage ( ) {
6148 if ( fs . existsSync ( system . typePath ) ) rimraf ( system . typePath ) ;
6249 if ( ! fs . existsSync ( `${ system . rootDir } /ffmpeg` ) ) fs . mkdirSync ( `${ system . rootDir } /ffmpeg` ) ;
@@ -71,11 +58,13 @@ async function getPackage(){
7158 } ) ;
7259 if ( ! downloaded ) console . error ( 'Unable to download files' ) ;
7360 console . log ( 'Unzipping files...' ) ;
74- var temp = ( system . zipPath . indexOf ( '.xz' ) !== - 1 ) ? await decompressXZ ( system . zipPath ) : await decompressZip ( system . zipPath ) ;
61+ var temp = ( system . zipPath . indexOf ( '.xz' ) !== - 1 ) ? await decompressXZ ( system . zipPath ) : decompressZip ( system . zipPath ) ;
7562
7663 console . log ( 'Unzipped files' ) ;
7764 fs . unlinkSync ( system . zipPath ) ;
78- forceRename ( temp , system . typePath ) ;
65+
66+ console . log ( 'Renaming files' ) ;
67+ fs . renameSync ( temp , system . typePath ) ;
7968
8069 console . log ( 'FFmpeg downloaded!' ) ;
8170}
0 commit comments