Skip to content

Commit 7e31bb6

Browse files
committed
Switch to adm-zip
1 parent a5f0641 commit 7e31bb6

3 files changed

Lines changed: 14 additions & 94 deletions

File tree

lib/download.js

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const fs = require('fs');
22
const request = require('request');
33
const tar = require('tar');
4-
const extract = require('extract-zip');
4+
const AdmZip = require('adm-zip');
55
const lzma = require('lzma-native');
66
const system = require('./system');
77
const console = require('./console');
@@ -28,12 +28,9 @@ function decompressXZ(file) {
2828
});
2929
}
3030
function 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

3936
function 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-
6047
async 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
}

package-lock.json

Lines changed: 5 additions & 74 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
},
2727
"homepage": "https://github.com/PotatoParser/ffmpeg-cli#readme",
2828
"dependencies": {
29-
"extract-zip": "^1.7.0",
29+
"adm-zip": "^0.4.14",
3030
"lzma-native": "^5.0.1",
3131
"progress": "^2.0.3",
3232
"request": "^2.88.2",

0 commit comments

Comments
 (0)