@ps-aux/nodebup 0.9.8 → 0.9.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,9 +3,7 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.Zipper = void 0;
|
7
|
-
|
8
|
-
var _admZip = _interopRequireDefault(require("adm-zip"));
|
6
|
+
exports.buildZipFromDirectory = exports.Zipper = void 0;
|
9
7
|
|
10
8
|
var _inversify = require("inversify");
|
11
9
|
|
@@ -15,35 +13,97 @@ var _unzipper = _interopRequireDefault(require("unzipper"));
|
|
15
13
|
|
16
14
|
var _nodeFs = _interopRequireDefault(require("node:fs"));
|
17
15
|
|
18
|
-
var
|
16
|
+
var _jszip = _interopRequireDefault(require("jszip"));
|
17
|
+
|
18
|
+
var _path = _interopRequireDefault(require("path"));
|
19
|
+
|
20
|
+
var _promises = _interopRequireDefault(require("stream/promises"));
|
21
|
+
|
22
|
+
var _Shell = require("../shell/Shell");
|
23
|
+
|
24
|
+
var _dec, _dec2, _dec3, _class;
|
19
25
|
|
20
26
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
21
27
|
|
22
28
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
23
29
|
|
24
|
-
let Zipper = (_dec = (0, _inversify.injectable)(), _dec(_class = class Zipper {
|
25
|
-
constructor() {
|
30
|
+
let Zipper = (_dec = (0, _inversify.injectable)(), _dec2 = Reflect.metadata("design:type", Function), _dec3 = Reflect.metadata("design:paramtypes", [typeof _Shell.Shell === "undefined" ? Object : _Shell.Shell]), _dec(_class = _dec2(_class = _dec3(_class = class Zipper {
|
31
|
+
constructor(sh) {
|
32
|
+
this.sh = sh;
|
33
|
+
|
26
34
|
_defineProperty(this, "log", (0, _logging.classObjLog)(this));
|
27
35
|
|
28
|
-
_defineProperty(this, "zipDir", async (
|
29
|
-
|
36
|
+
_defineProperty(this, "zipDir", async (dirPath, to) => {
|
37
|
+
const src = dirPath.str();
|
38
|
+
const dst = to.str();
|
39
|
+
|
40
|
+
const dstDir = _path.default.dirname(dst);
|
41
|
+
|
42
|
+
this.log.trace(`Zipping %s to %s`, src, dst);
|
43
|
+
|
44
|
+
if (!_nodeFs.default.existsSync(dstDir)) {
|
45
|
+
_nodeFs.default.mkdirSync(dstDir);
|
46
|
+
}
|
47
|
+
|
48
|
+
await this.doDirZipInShell(src, dst);
|
49
|
+
});
|
50
|
+
|
51
|
+
_defineProperty(this, "doDirZipInShell", async (src, dst) => {
|
52
|
+
await this.sh.exec(`zip ${dst} -r .`, {
|
53
|
+
cwd: src
|
54
|
+
});
|
55
|
+
});
|
56
|
+
|
57
|
+
_defineProperty(this, "doDirZipInNodeJs", async (src, dst) => {
|
58
|
+
const zip = new _jszip.default();
|
59
|
+
buildZipFromDirectory(src, zip);
|
60
|
+
const r = await zip.generateNodeStream();
|
61
|
+
|
62
|
+
const ws = _nodeFs.default.createWriteStream(dst);
|
30
63
|
|
31
|
-
|
32
|
-
z.addLocalFolder(dir.str());
|
33
|
-
z.writeZip(to.str());
|
64
|
+
await _promises.default.pipeline(r, ws);
|
34
65
|
});
|
35
66
|
|
36
67
|
_defineProperty(this, "unzipDir", async (zipFile, toDir) => {
|
68
|
+
// TODO can be replaced with JsZip ?
|
37
69
|
this.log.trace(`Unzipping %s to %s`, zipFile.str(), toDir.str());
|
70
|
+
|
71
|
+
const input = _nodeFs.default.createReadStream(zipFile.str());
|
72
|
+
|
73
|
+
const out = _unzipper.default.Extract({
|
74
|
+
path: toDir.str()
|
75
|
+
}); // Cannot use Streams.pipeline bcs it sometimes resolves before the file exists
|
76
|
+
|
77
|
+
|
38
78
|
return new Promise((res, rej) => {
|
39
|
-
|
40
|
-
path: toDir.str()
|
41
|
-
})).on('close', () => {
|
79
|
+
input.pipe(out).on('close', () => {
|
42
80
|
res();
|
43
81
|
}).on('error', rej);
|
44
82
|
});
|
45
83
|
});
|
46
84
|
}
|
47
85
|
|
48
|
-
}) || _class);
|
49
|
-
exports.Zipper = Zipper;
|
86
|
+
}) || _class) || _class) || _class);
|
87
|
+
exports.Zipper = Zipper;
|
88
|
+
|
89
|
+
const buildZipFromDirectory = (dir, zip, root = dir) => {
|
90
|
+
const list = _nodeFs.default.readdirSync(dir);
|
91
|
+
|
92
|
+
for (let file of list) {
|
93
|
+
file = _path.default.resolve(dir, file);
|
94
|
+
|
95
|
+
const stat = _nodeFs.default.statSync(file);
|
96
|
+
|
97
|
+
if (stat && stat.isDirectory()) {
|
98
|
+
buildZipFromDirectory(file, zip, root);
|
99
|
+
} else {
|
100
|
+
const filedata = _nodeFs.default.createReadStream(file);
|
101
|
+
|
102
|
+
const p = _path.default.relative(root, file);
|
103
|
+
|
104
|
+
zip.file(p, filedata);
|
105
|
+
}
|
106
|
+
}
|
107
|
+
};
|
108
|
+
|
109
|
+
exports.buildZipFromDirectory = buildZipFromDirectory;
|
@@ -8,12 +8,15 @@ var _testHelper = require("../../../test/testHelper");
|
|
8
8
|
|
9
9
|
var _test = require("../../../test");
|
10
10
|
|
11
|
+
var _Shell = require("../shell/Shell");
|
12
|
+
|
11
13
|
describe('zip', () => {
|
12
14
|
afterEach(() => {
|
13
15
|
(0, _testHelper.cleanTestDataDir)();
|
14
16
|
});
|
15
17
|
it('zip and unzip', async () => {
|
16
|
-
const
|
18
|
+
const sh = new _Shell.Shell();
|
19
|
+
const z = new _Zipper.Zipper(sh);
|
17
20
|
const out = (0, _test.testdataDirPath)('out.zip');
|
18
21
|
|
19
22
|
const dir = _Path.AbsPath.from(__dirname).resolve('../../../test/foo');
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@ps-aux/nodebup",
|
3
|
-
"version": "0.9.
|
3
|
+
"version": "0.9.10",
|
4
4
|
"description": "",
|
5
5
|
"module": "lib/index.js",
|
6
6
|
"main": "lib/index.js",
|
@@ -80,12 +80,12 @@
|
|
80
80
|
"@hapi/joi": "^17.1.1",
|
81
81
|
"@ps-aux/nclif": "^0.0.7-alpha.1",
|
82
82
|
"@types/hapi__joi": "^17.1.8",
|
83
|
-
"adm-zip": "^0.5.9",
|
84
83
|
"axios": "^0.24.0",
|
85
84
|
"handlebars": "^4.7.7",
|
86
85
|
"ini": "^2.0.0",
|
87
86
|
"inversify": "^6.0.1",
|
88
87
|
"js-yaml": "^4.1.0",
|
88
|
+
"jszip": "^3.10.1",
|
89
89
|
"pino": "^7.11.0",
|
90
90
|
"pino-pretty": "^9.1.1",
|
91
91
|
"ramda": "^0.27.1",
|