Skip to content

Commit 6badf28

Browse files
committed
refactor to allow retrying using 7za when full 7z fails, which is the case on Linux and Mac OS, bug fix, update Readme
1 parent 2721c8c commit 6badf28

18 files changed

+164
-84
lines changed

README.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ __How to create Sfx - Self Extracting Archives.__
3737
Executables will be built using 7-zip version _19.00_ on **Windows OS** for Windows targets.
3838
**Linux** and **Apple macOS** will use 7-zip version _16.04_ for all targets.
3939

40-
import { createWindowsSfx, createLinuxSfx, createMacSfx } from 'node-7z-archive';
40+
import { createSfxWindows, createSfxLinux, createSfxMac } from 'node-7z-archive';
4141

42-
- **createWindowsSfx**(name, files, destination, options, type);
42+
- **createSfxWindows**(name, files, destination, options, type);
4343

44-
- **createLinuxSfx**(name, files, destination, options);
44+
- **createSfxLinux**(name, files, destination, options);
4545

46-
- **createMacSfx**(name, files, destination, options);
46+
- **createSfxMac**(name, files, destination, options);
4747

4848
Each will in turn call:
4949
**createSfx**(name, files, destination, options, type, platform, extension) as:
@@ -98,7 +98,7 @@ For using full **7zip** from command line without installation package.
9898
npm install -g node-7z-archive
9999
```
100100

101-
Will have **`createArchive`, `deleteArchive`, `extractArchive`, `fullArchive`, `listArchive`, `renameArchive`, `testArchive`, `updateArchive`** available globally. To always see available commands type:
101+
Will have **`createArchive`, `deleteArchive`, `extractArchive`, `fullArchive`, `listArchive`, `renameArchive`, `testArchive`, `updateArchive`**, **`createSfx`** available globally. To always see available commands, and binary location type:
102102

103103
```shell
104104
7zip
@@ -136,6 +136,12 @@ Full 7zip Console Commands.
136136

137137
Update older files in the archive and add files that are not already in the archive.
138138
Usage: `updateArchive` archivePath files ...options
139+
140+
Create an Sfx - self extracting installation package for targeted platform.
141+
Usage: `createSfx` platform packageName files -destination ...options
142+
143+
-----------------------------------------------------------------
144+
The `7z` and `7za` binary on your system is located in directory: ...\...\node-7z-archive\binaries\...
139145
```
140146

141147
> ____This package is a rewrite of [node-7z-forall](https://github.com/techno-express/node-7z-forall)____. The original author has removed the version it was a fork of [node-7z](https://github.com/quentinrossetti/node-7z). The author's current version has over `600` dependency tree without dev. This package dependency is `130` with dev.

cli/7zip.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88
* Dependencies.
99
*/
1010
import minimist from 'minimist';
11+
import platformBinary from '../util/binary.mjs';
1112
import {
1213
createRequire
1314
} from 'module';
1415

1516
const require = createRequire(
1617
import.meta.url);
17-
const pack = require('../package.json');
18+
const pack = require('../package.json'),
19+
sevenBinary = platformBinary();
1820

1921
/*
2022
* Arguments.
@@ -62,6 +64,12 @@ function help() {
6264
'',
6365
'Update older files in the archive and add files that are not already in the archive.',
6466
'Usage: `updateArchive` archivePath files ...options',
67+
'',
68+
'Create an Sfx - self extracting installation package for targeted platform.',
69+
'Usage: `createSfx` platform packageName files -destination ...options',
70+
'',
71+
'----------------------------------------------------------------',
72+
'The `7z` and `7za` binary on your system is located in directory: ' + sevenBinary.path,
6573
].join('\n ') + '\n';
6674
}
6775

lib/createArchive.mjs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,19 @@ export default function (filepath, files, options, override = false) {
5454
})
5555

5656
// Catch the error and pass it to the reject function of the Promise.
57-
.catch(function (err) {
58-
return reject(err);
57+
.catch(function () {
58+
console.error('CreateArchive failed using `7z`, retying with `7za`.');
59+
Run('7za', command, options, override)
60+
.progress(function (data) {
61+
return progress(onprogress(data));
62+
})
63+
64+
.then(function (args) {
65+
return resolve(args);
66+
})
67+
.catch(function (err) {
68+
return reject(err);
69+
});
5970
});
6071
});
6172
};

lib/createSfx.mjs

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ export default function (
160160
sfx: sfxModule
161161
});
162162

163-
return createArchive(sfx, list, params, '7z', override)
163+
createArchive(sfx, list, params, override)
164164
.progress((data) => {
165165
return progress(data);
166166
})
@@ -176,28 +176,9 @@ export default function (
176176
}
177177
});
178178
})
179-
.catch(() => {
180-
// Override try different binary
181-
return createArchive(sfx, list, params, override)
182-
.progress((data) => {
183-
return progress(data);
184-
})
185-
.then((data) => {
186-
fs.unlink(configFile, (err) => {
187-
if (err) console.error(err);
188-
if (fs.existsSync(sfx)) {
189-
return resolve(sfx);
190-
/* c8 ignore next 4 */
191-
} else {
192-
console.error(data);
193-
return reject('Failed! The Sfx application could not be created!');
194-
}
195-
});
196-
})
197-
.catch((err) => {
198-
fs.removeSync(configFile);
199-
return reject(err);
200-
});
179+
.catch((err) => {
180+
fs.removeSync(configFile);
181+
return reject(err);
201182
});
202183
});
203184
}

lib/deleteArchive.mjs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,15 @@ export default function (filepath, files, options, override = false) {
3434
})
3535

3636
// Catch the error and pass it to the reject function of the Promise.
37-
.catch(function (err) {
38-
return reject(err);
37+
.catch(function () {
38+
console.error('DeleteArchive failed using `7z`, retying with `7za`.');
39+
Run('7za', command, options, override)
40+
.then(function (args) {
41+
return resolve(args);
42+
})
43+
.catch(function (err) {
44+
return reject(err);
45+
});
3946
});
40-
4147
});
4248
};

lib/extractArchive.mjs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,18 @@ export default function (filepath, dest = '*', options = {}, override = false) {
5050
})
5151

5252
// Catch the error and pass it to the reject function of the Promise.
53-
.catch(function (err) {
54-
return reject(err);
53+
.catch(function () {
54+
console.error('ExtractArchive failed using `7z`, retying with `7za`.');
55+
Run('7za', command, options, override)
56+
.progress(function (data) {
57+
return progress(onprogress(data));
58+
})
59+
.then(function (args) {
60+
return resolve(args);
61+
})
62+
.catch(function (err) {
63+
return reject(err);
64+
});
5565
});
5666
});
5767
};

lib/fullArchive.mjs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,18 @@ export default function (filepath, dest = '*', options = {}, override = false) {
4545
.then(function (args) {
4646
return resolve(args);
4747
})
48-
.catch(function (err) {
49-
return reject(err);
48+
.catch(function () {
49+
console.error('FullArchive failed using `7z`, retying with `7za`.');
50+
Run('7za', command, options, override)
51+
.progress(function (data) {
52+
return progress(onprogress(data));
53+
})
54+
.then(function (args) {
55+
return resolve(args);
56+
})
57+
.catch(function (err) {
58+
return reject(err);
59+
});
5060
});
5161
});
5262
};

lib/index.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ export const renameArchive = SevenZip.renameArchive = _renameArchive;
2424
export const testArchive = SevenZip.testArchive = _testArchive;
2525
export const updateArchive = SevenZip.updateArchive = _updateArchive;
2626

27-
export const createWindowsSfx = SevenZip.windowsSfx = function (name, files, destination, options, type) {
27+
export const createSfxWindows = SevenZip.windowsSfx = function (name, files, destination, options, type) {
2828
return createSfx(name, files, destination, options, type, 'win32', '.exe');
2929
};
3030

31-
export const createLinuxSfx = SevenZip.linuxSfx = function (name, files, destination, options) {
31+
export const createSfxLinux = SevenZip.linuxSfx = function (name, files, destination, options) {
3232
return createSfx(name, files, destination, options, 'console', 'linux', '.elf');
3333
};
3434

35-
export const createMacSfx = SevenZip.macSfx = function (name, files, destination, options) {
35+
export const createSfxMac = SevenZip.macSfx = function (name, files, destination, options) {
3636
return createSfx(name, files, destination, options, 'console', 'darwin', '.pkg');
3737
};

lib/listArchive.mjs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,18 @@ export default function (filepath, options, override = false) {
7979
.then(function () {
8080
return resolve(spec);
8181
})
82-
.catch(function (err) {
83-
return reject(err);
82+
.catch(function () {
83+
console.error('ListArchive failed using `7z`, retying with `7za`.');
84+
Run('7za', command, options, override)
85+
.progress(function (data) {
86+
return progress(onprogress(data));
87+
})
88+
.then(function (args) {
89+
return resolve(args);
90+
})
91+
.catch(function (err) {
92+
return reject(err);
93+
});
8494
});
8595
});
8696
};

lib/renameArchive.mjs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,18 @@ export default function (filepath, files, options, override = false) {
5050
.then(function () {
5151
return resolve();
5252
})
53-
.catch(function (err) {
54-
return reject(err);
53+
.catch(function () {
54+
console.error('RenameArchive failed using `7z`, retying with `7za`.');
55+
Run('7za', command, options, override)
56+
.progress(function (data) {
57+
return progress(onprogress(data));
58+
})
59+
.then(function (args) {
60+
return resolve(args);
61+
})
62+
.catch(function (err) {
63+
return reject(err);
64+
});
5565
});
5666
});
5767
};

0 commit comments

Comments
 (0)