Skip to content

Commit 837f188

Browse files
committed
bug fix only files extraction routine, update readme, version, and cli tools
1 parent b476edb commit 837f188

File tree

13 files changed

+177
-36
lines changed

13 files changed

+177
-36
lines changed

README.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ Each will in turn call:
7272
* `platform` What platform application targeting? Either `win32`, `darwin`, or `linux`.
7373
* `extension` Binary extension name.
7474

75-
7675
Installation
7776
------------
7877

@@ -85,7 +84,6 @@ The binaries will be downloaded from:
8584
8685
> On Mac OSX - [![Release](https://github.com/techno-express/p7zip/workflows/Release/badge.svg)](https://github.com/techno-express/p7zip/actions/runs/401873413) compiled and available at [releases](https://github.com/techno-express/p7zip/releases/) previously https://rudix.org/.
8786
88-
8987
```shell
9088
npm install --save node-7z-archive
9189
```
@@ -126,6 +124,9 @@ Full 7zip Console Commands.
126124
Extracts files from an archive with their full paths in the current directory, or in an output directory
127125
Usage: `fullArchive` archivePath destination ...options
128126

127+
Extracts only the selected files from an archive to the current directory, or in an output directory
128+
Usage: `onlyArchive` archivePath destination files ...options'
129+
129130
Lists contents of archive.
130131
Usage: `listArchive` archivePath ...options
131132

@@ -283,6 +284,21 @@ _____Options:_____ 7-Zip Switches, use without initial `'-'`.
283284
**Error**
284285
* `err` An Error object.
285286

287+
### `onlyArchive`(filepath, dest, files, options)
288+
289+
**Arguments**
290+
* `filepath` The path to the archive you want to extract selected files from.
291+
* `dest` Where to extract with full paths, the archive (creates folders for you).
292+
* `files` What files to extract, will overwrite if file exits.
293+
* `options` An object of options.
294+
295+
**Progress**
296+
* `files` A array of all the extracted files *AND* directories. The `/`
297+
character is used as a path separator on every platform.
298+
299+
**Error**
300+
* `err` An Error object.
301+
286302
### `renameArchive`(filepath, files, options)
287303

288304
**Arguments**

cli/7zip.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ function help() {
5353
'Extracts files from an archive with their full paths in the current directory, or in an output directory',
5454
'Usage: `fullArchive` archivePath destination ...options',
5555
'',
56+
'Extracts only the selected files from an archive to the current directory, or in an output directory',
57+
'Usage: `onlyArchive` archivePath destination files ...options',
58+
'',
5659
'Lists contents of archive.',
5760
'Usage: `listArchive` archivePath ...options',
5861
'',

cli/only.js

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#!/usr/bin/env node
2+
3+
'use strict';
4+
5+
/* eslint-disable no-process-exit */
6+
7+
/*
8+
* Dependencies.
9+
*/
10+
import {
11+
onlyArchive
12+
} from '../lib/index.mjs';
13+
import minimist from 'minimist';
14+
import {
15+
createRequire
16+
} from 'module';
17+
18+
const require = createRequire(
19+
import.meta.url);
20+
const pack = require('../package.json');
21+
22+
/*
23+
* Arguments.
24+
*/
25+
let argv = minimist(process.argv.slice(2));
26+
27+
/*
28+
* Command.
29+
*/
30+
var command = Object.keys(pack.bin)[6];
31+
32+
/**
33+
* Help.
34+
*
35+
* @return {string}
36+
*/
37+
function help() {
38+
return [
39+
'Extracts only the selected files from an archive to the current directory, or in an output directory',
40+
'Usage: ' + command + ' [filepath] [destination] [files] ...Options',
41+
'',
42+
pack.description,
43+
'',
44+
' [filepath] - Path to the archive.',
45+
' [destination] - Output destination path.',
46+
' [files] - Files in archive to extract.',
47+
'',
48+
'Options:',
49+
'',
50+
' -h, --help output usage information',
51+
' -v, --version output version number',
52+
'',
53+
' Any of these 7zip switches this command accepts:',
54+
'',
55+
' -ai (Include archive filenames)',
56+
' -an (Disable parsing of archive_name)',
57+
' -ao (Overwrite mode)',
58+
' -ax (Exclude archive filenames)',
59+
' -i (Include filenames)',
60+
' -m (Set compression Method)',
61+
' -p (Set Password)',
62+
' -r (Recurse subdirectories)',
63+
' -si (read data from stdin)',
64+
' -sni (Store NT security information)',
65+
' -sns (Store NTFS alternate Streams)',
66+
' -so (write data to stdout)',
67+
' -spf (Use fully qualified file paths)',
68+
' -t (set Type of archive)',
69+
' -x (Exclude filenames)',
70+
' -y (assume Yes on all queries)',
71+
'',
72+
'Example:',
73+
'> ' + command + ' disc/master.7z home/support.js -y',
74+
''
75+
].join('\n ') + '\n';
76+
}
77+
78+
/*
79+
* Program.
80+
*/
81+
if (argv.help || argv.h) {
82+
console.log(help());
83+
} else if (argv.version || argv.v) {
84+
console.log(pack.version);
85+
} else if (argv) {
86+
let options = {};
87+
let files = argv._;
88+
let filepath = files.shift();
89+
destination = files.shift();
90+
delete argv._;
91+
if (filepath && destination && files) {
92+
options = Object.assign(options, argv)
93+
console.log("Extracting files...");
94+
onlyArchive(filepath, destination, files, options)
95+
.progress((info) => {
96+
console.log(info);
97+
})
98+
.then(() => {
99+
console.log('Extraction of files from archive ' + filepath + ' to ' + destination + ' done!');
100+
})
101+
.catch((error) => {
102+
console.log('--- error:');
103+
console.log(error);
104+
});
105+
} else {
106+
console.log(help());
107+
}
108+
} else {
109+
console.log(help());
110+
}

cli/rename.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ let argv = minimist(process.argv.slice(2));
2727
/*
2828
* Command.
2929
*/
30-
var command = Object.keys(pack.bin)[6];
30+
var command = Object.keys(pack.bin)[7];
3131

3232
/**
3333
* Help.

cli/sfx.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ let argv = minimist(process.argv.slice(2));
3535
/*
3636
* Command.
3737
*/
38-
var command = Object.keys(pack.bin)[7];
38+
var command = Object.keys(pack.bin)[8];
3939

4040
/**
4141
* Help.
@@ -131,8 +131,8 @@ if (argv.help || argv.h) {
131131
if (packageName && files && typeof sfxPromise.then === 'function') {
132132
console.log("Creating Sfx Package...");
133133
sfxPromise.progress((info) => {
134-
console.log(info);
135-
})
134+
console.log(info);
135+
})
136136
.then((file) => {
137137
console.log('Creation of installation package ' + packageName + ' saved to ' + file + ' done!');
138138
})

cli/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ let argv = minimist(process.argv.slice(2));
2727
/*
2828
* Command.
2929
*/
30-
var command = Object.keys(pack.bin)[8];
30+
var command = Object.keys(pack.bin)[9];
3131

3232
/**
3333
* Help.

cli/update.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ let argv = minimist(process.argv.slice(2));
2727
/*
2828
* Command.
2929
*/
30-
var command = Object.keys(pack.bin)[9];
30+
var command = Object.keys(pack.bin)[10];
3131

3232
/**
3333
* Help.

lib/onlyArchive.mjs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
22

33
import when from 'when';
4-
import Files from '../util/files.mjs';
54
import ReplaceNativeSeparator from '../util/replaceNativeSeparator.mjs';
65
import Run from '../util/run.mjs';
76

@@ -20,8 +19,10 @@ import Run from '../util/run.mjs';
2019
*
2120
* @returns {Promise} Promise
2221
*/
23-
export default function (filepath, dest = '*', files = [], options = {}, override = false) {
22+
export default function (filepath, dest, files, options = {}, override = false) {
2423
return when.promise(function (resolve, reject, progress) {
24+
options = Object.assign(options, { files: files });
25+
2526
/**
2627
* When a stdout is emitted, parse each line and search for a pattern.When
2728
* the pattern is found, extract the file (or directory) name from it and
@@ -37,11 +38,8 @@ export default function (filepath, dest = '*', files = [], options = {}, overrid
3738
return entries;
3839
}
3940

40-
// Convert array of files into a string if needed.
41-
files = Files(files);
42-
4341
// Create a string that can be parsed by `run`.
44-
let command = 'e "' + filepath + '" -o"' + dest + '" -r -aos ' + files;
42+
let command = 'e "' + filepath + '" -o"' + dest + '"';
4543

4644
// Start the command
4745
Run('7z', command, options, override)

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-7z-archive",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "ESM front-end to 7-Zip, featuring alternative full 7z CLI tools, binaries for Linux, Windows, Mac OSX, seamlessly create 7zip SFX self extracting archives targeting different platforms.",
55
"type": "module",
66
"main": "lib/index.mjs",
@@ -63,6 +63,7 @@
6363
"extractArchive": "cli/extract.js",
6464
"fullArchive": "cli/full.js",
6565
"listArchive": "cli/list.js",
66+
"onlyArchive": "cli/only.js",
6667
"renameArchive": "cli/rename.js",
6768
"createSfx": "cli/sfx.js",
6869
"testArchive": "cli/test.js",

0 commit comments

Comments
 (0)