-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharchiver.js
More file actions
69 lines (57 loc) · 1.87 KB
/
Copy patharchiver.js
File metadata and controls
69 lines (57 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/**
* @file Front-end for extracting from jag archives.
*/
const argv = require('yargs')
.option('d', {
alias: 'destination',
default: process.cwd,
describe: 'Directory to extract the entries to.'
})
.option('e', {
alias: 'extract',
default: '',
describe: 'Entry to be extracted from the given archive.\n\
If no arguments are given, all of the entries will be extracted.'
})
.option('i', {
alias: 'input',
demandOption: true,
describe: 'Path to the archive to extract from.'
})
.parse();
const fs = require('fs');
const path = require('path');
const jagarc = require('./jagarc.js');
const archive = new jagarc.JagArchive();
if (typeof(argv.input) !== 'string') {
return console.error('Input option must have an argument');
}
jagarc.loadArchive(archive, argv.input, err => {
if (err) {
return console.error(err);
}
let entriesRequested = [];
if (argv.extract && typeof(argv.extract) === 'string') {
entriesRequested = argv.extract.split(' ');
} else {
entriesRequested = 'all';
}
if (entriesRequested === 'all') {
for (let entryIdx in archive.entries) {
const entry = archive.entries[entryIdx];
const fileName = entryIdx;
const filePath = path.join(argv.destination, fileName);
fs.writeFileSync(filePath, entry.data);
}
} else {
for (let entryIdx in entriesRequested) {
const entryName = entriesRequested[entryIdx];
const entryData = archive.get(entryName);
if (!entryData) {
return console.error('Failed to find entry: ' + entryName + '.');
}
const filePath = path.join(argv.destination, entryName);
fs.writeFileSync(filePath, entryData);
}
}
});