Skip to content

Commit 5adc6b1

Browse files
committed
🐳 chore(android): add script to compress vpn jni
1 parent e7af712 commit 5adc6b1

File tree

4 files changed

+295
-3
lines changed

4 files changed

+295
-3
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,6 @@ local.properties
4040
buck-out/
4141
\.buckd/
4242
*.keystore
43+
44+
# Other
45+
vpnJni/*.zip

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"build-vpn-lib": "yarn build-ics-ovpn; yarn gen-vpn-lib; yarn patch-vpn-lib",
1919
"build-ics-ovpn": "sh scripts/build-ics-ovpn.sh",
2020
"gen-vpn-lib": "sh scripts/gen-vpn-lib.sh",
21-
"patch-vpn-lib": "sh scripts/patch-vpn-lib.sh"
21+
"patch-vpn-lib": "sh scripts/patch-vpn-lib.sh",
22+
"zip-vpn-jni": "node vpnJni/zip-vpn-jni.js"
2223
},
2324
"repository": {
2425
"type": "git",
@@ -38,6 +39,7 @@
3839
"licenseFilename": "LICENSE",
3940
"readmeFilename": "README.md",
4041
"devDependencies": {
42+
"archiver": "^5.3.0",
4143
"clang-format": "^1.4.0",
4244
"prettier": "^2.3.2"
4345
}

vpnJni/zip-vpn-jni.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const fs = require('fs');
2+
const archiver = require('archiver');
3+
4+
const jniLibPath = __dirname + '/../vpnLib/src/main/jniLibs';
5+
const jniDirList = fs.readdirSync(jniLibPath);
6+
7+
jniDirList.forEach((item) => {
8+
if (item === '.DS_Store') return;
9+
10+
const output = fs.createWriteStream(`${__dirname}/${item}.zip`);
11+
const archive = archiver('zip', {
12+
zlib: { level: 9 },
13+
});
14+
15+
output.on('close', () => {
16+
const compressedSize = (archive.pointer() / 1024 / 1024).toFixed(2);
17+
console.log(`Finish compressing [${item}] - ${compressedSize} MB`);
18+
});
19+
20+
output.on('end', () => {
21+
console.log('Data has been drained');
22+
});
23+
24+
archive.on('warning', (err) => {
25+
if (err.code === 'ENOENT') {
26+
console.log('Warning ' + err);
27+
} else {
28+
throw err;
29+
}
30+
});
31+
32+
archive.on('error', (err) => {
33+
throw err;
34+
});
35+
36+
archive.pipe(output);
37+
archive.directory(`${jniLibPath}/${item}/`, false);
38+
archive.finalize();
39+
});

0 commit comments

Comments
 (0)