@spinajs/fs 2.0.180 → 2.0.181
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.
- package/lib/cjs/cli/rm.d.ts +11 -11
- package/lib/cjs/cli/rm.js +28 -28
- package/lib/cjs/cli/rm.js.map +1 -1
- package/lib/cjs/cli/stat.d.ts +10 -10
- package/lib/cjs/cli/stat.js +26 -26
- package/lib/cjs/cli/stat.js.map +1 -1
- package/lib/cjs/config/fs.d.ts +33 -16
- package/lib/cjs/config/fs.d.ts.map +1 -1
- package/lib/cjs/config/fs.js +50 -36
- package/lib/cjs/config/fs.js.map +1 -1
- package/lib/cjs/decorators.d.ts +7 -7
- package/lib/cjs/decorators.js +23 -23
- package/lib/cjs/file-hasher.d.ts +12 -8
- package/lib/cjs/file-hasher.d.ts.map +1 -1
- package/lib/cjs/file-hasher.js +51 -42
- package/lib/cjs/file-hasher.js.map +1 -1
- package/lib/cjs/file-info.d.ts +10 -10
- package/lib/cjs/file-info.js +124 -124
- package/lib/cjs/file-info.js.map +1 -1
- package/lib/cjs/index.d.ts +10 -10
- package/lib/cjs/index.d.ts.map +1 -1
- package/lib/cjs/index.js +72 -71
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/interfaces.d.ts +180 -157
- package/lib/cjs/interfaces.d.ts.map +1 -1
- package/lib/cjs/interfaces.js +44 -33
- package/lib/cjs/interfaces.js.map +1 -1
- package/lib/cjs/local-provider.d.ts +96 -100
- package/lib/cjs/local-provider.d.ts.map +1 -1
- package/lib/cjs/local-provider.js +321 -278
- package/lib/cjs/local-provider.js.map +1 -1
- package/lib/cjs/local-temp-provider.d.ts +18 -18
- package/lib/cjs/local-temp-provider.d.ts.map +1 -1
- package/lib/cjs/local-temp-provider.js +59 -54
- package/lib/cjs/local-temp-provider.js.map +1 -1
- package/lib/mjs/cli/rm.d.ts +11 -11
- package/lib/mjs/cli/rm.js +25 -25
- package/lib/mjs/cli/rm.js.map +1 -1
- package/lib/mjs/cli/stat.d.ts +10 -10
- package/lib/mjs/cli/stat.js +23 -23
- package/lib/mjs/cli/stat.js.map +1 -1
- package/lib/mjs/config/fs.d.ts +33 -16
- package/lib/mjs/config/fs.d.ts.map +1 -1
- package/lib/mjs/config/fs.js +48 -34
- package/lib/mjs/config/fs.js.map +1 -1
- package/lib/mjs/decorators.d.ts +7 -7
- package/lib/mjs/decorators.js +19 -19
- package/lib/mjs/file-hasher.d.ts +12 -8
- package/lib/mjs/file-hasher.d.ts.map +1 -1
- package/lib/mjs/file-hasher.js +45 -36
- package/lib/mjs/file-hasher.js.map +1 -1
- package/lib/mjs/file-info.d.ts +10 -10
- package/lib/mjs/file-info.js +121 -121
- package/lib/mjs/file-info.js.map +1 -1
- package/lib/mjs/index.d.ts +10 -10
- package/lib/mjs/index.d.ts.map +1 -1
- package/lib/mjs/index.js +55 -54
- package/lib/mjs/index.js.map +1 -1
- package/lib/mjs/interfaces.d.ts +180 -157
- package/lib/mjs/interfaces.d.ts.map +1 -1
- package/lib/mjs/interfaces.js +38 -27
- package/lib/mjs/interfaces.js.map +1 -1
- package/lib/mjs/local-provider.d.ts +96 -100
- package/lib/mjs/local-provider.d.ts.map +1 -1
- package/lib/mjs/local-provider.js +315 -272
- package/lib/mjs/local-provider.js.map +1 -1
- package/lib/mjs/local-temp-provider.d.ts +18 -18
- package/lib/mjs/local-temp-provider.d.ts.map +1 -1
- package/lib/mjs/local-temp-provider.js +56 -51
- package/lib/mjs/local-temp-provider.js.map +1 -1
- package/lib/tsconfig.cjs.tsbuildinfo +1 -1
- package/lib/tsconfig.mjs.tsbuildinfo +1 -1
- package/package.json +6 -2
|
@@ -1,279 +1,322 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.fsNative = void 0;
|
|
16
|
-
/* eslint-disable security/detect-non-literal-fs-filename */
|
|
17
|
-
const exceptions_1 = require("@spinajs/exceptions");
|
|
18
|
-
const fs_1 = require("fs");
|
|
19
|
-
const promises_1 = require("node:fs/promises");
|
|
20
|
-
const luxon_1 = require("luxon");
|
|
21
|
-
const di_1 = require("@spinajs/di");
|
|
22
|
-
const interfaces_js_1 = require("./interfaces.js");
|
|
23
|
-
const path_1 = require("path");
|
|
24
|
-
const log_common_1 = require("@spinajs/log-common");
|
|
25
|
-
const archiver_1 = __importDefault(require("archiver"));
|
|
26
|
-
const unzipper_1 = __importDefault(require("unzipper"));
|
|
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
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
(0,
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
*
|
|
133
|
-
* @param
|
|
134
|
-
*/
|
|
135
|
-
async
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
*
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
async
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
const
|
|
235
|
-
const
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.fsNative = void 0;
|
|
16
|
+
/* eslint-disable security/detect-non-literal-fs-filename */
|
|
17
|
+
const exceptions_1 = require("@spinajs/exceptions");
|
|
18
|
+
const fs_1 = require("fs");
|
|
19
|
+
const promises_1 = require("node:fs/promises");
|
|
20
|
+
const luxon_1 = require("luxon");
|
|
21
|
+
const di_1 = require("@spinajs/di");
|
|
22
|
+
const interfaces_js_1 = require("./interfaces.js");
|
|
23
|
+
const path_1 = require("path");
|
|
24
|
+
const log_common_1 = require("@spinajs/log-common");
|
|
25
|
+
const archiver_1 = __importDefault(require("archiver"));
|
|
26
|
+
const unzipper_1 = __importDefault(require("unzipper"));
|
|
27
|
+
const promises_2 = require("fs/promises");
|
|
28
|
+
const util_1 = require("@spinajs/util");
|
|
29
|
+
/**
|
|
30
|
+
* Abstract layer for file operations.
|
|
31
|
+
* Basic implementation is just wrapper for native node fs functions
|
|
32
|
+
*
|
|
33
|
+
* It allows to wrap other libs eg. aws s3, ftp
|
|
34
|
+
* and inject it into code without changing logic that use them.
|
|
35
|
+
*
|
|
36
|
+
* TODO: map errors to some kind of common errors shared with other implementations
|
|
37
|
+
*/
|
|
38
|
+
let fsNative = class fsNative extends interfaces_js_1.fs {
|
|
39
|
+
/**
|
|
40
|
+
* Name of provider. We can have multiple providers of the same type but with different options.
|
|
41
|
+
* Also used in InjectService decorator for mapping
|
|
42
|
+
*/
|
|
43
|
+
get Name() {
|
|
44
|
+
return this.Options.name;
|
|
45
|
+
}
|
|
46
|
+
constructor(Options) {
|
|
47
|
+
super();
|
|
48
|
+
this.Options = Options;
|
|
49
|
+
}
|
|
50
|
+
async resolve() {
|
|
51
|
+
if (!this.Options.basePath) {
|
|
52
|
+
throw new exceptions_1.IOFail(`Base path for file provider ${this.Options.name} not set`);
|
|
53
|
+
}
|
|
54
|
+
if ((await this.exists(this.Options.basePath)) === false) {
|
|
55
|
+
this.Logger.warn(`Base path ${this.Options.basePath} for file provider ${this.Options.name} not exists, trying to create base folder`);
|
|
56
|
+
await (0, promises_1.mkdir)(this.Options.basePath, { recursive: true });
|
|
57
|
+
this.Logger.success(`Base path ${this.Options.basePath} created`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
*
|
|
62
|
+
* Tries to download file to local filesystem, then returns local filesystem path.
|
|
63
|
+
* Native implementation simply returns local path and does nothing.
|
|
64
|
+
*
|
|
65
|
+
* @param path - file to download
|
|
66
|
+
*/
|
|
67
|
+
async download(path) {
|
|
68
|
+
const p = this.resolvePath(path);
|
|
69
|
+
const exists = await this.exists(path);
|
|
70
|
+
if (!exists) {
|
|
71
|
+
throw new exceptions_1.IOFail(`file ${p} does not exists`);
|
|
72
|
+
}
|
|
73
|
+
return p;
|
|
74
|
+
}
|
|
75
|
+
async upload(srcPath, destPath) {
|
|
76
|
+
if (!(0, fs_1.existsSync)(srcPath)) {
|
|
77
|
+
throw new exceptions_1.IOFail(`file ${srcPath} does not exists`);
|
|
78
|
+
}
|
|
79
|
+
const dPath = this.resolvePath(destPath ?? (0, path_1.basename)(srcPath));
|
|
80
|
+
await (0, promises_2.cp)(srcPath, dPath, { force: true, recursive: true });
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* read all content of file
|
|
84
|
+
*/
|
|
85
|
+
async read(path, encoding) {
|
|
86
|
+
return new Promise((resolve, reject) => {
|
|
87
|
+
(0, fs_1.readFile)(this.resolvePath(path), { encoding: encoding ?? 'binary' }, (err, data) => {
|
|
88
|
+
if (err) {
|
|
89
|
+
reject(err);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
resolve(data);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
readStream(path, encoding) {
|
|
98
|
+
return Promise.resolve((0, fs_1.createReadStream)(this.resolvePath(path), { encoding: encoding ?? 'binary' }));
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Write to file string or buffer
|
|
102
|
+
*/
|
|
103
|
+
async write(path, data, encoding) {
|
|
104
|
+
let fHandle = null;
|
|
105
|
+
try {
|
|
106
|
+
fHandle = await (0, promises_1.open)(this.resolvePath(path), 'w');
|
|
107
|
+
await fHandle.writeFile(data, { encoding });
|
|
108
|
+
}
|
|
109
|
+
catch (err) {
|
|
110
|
+
throw new exceptions_1.IOFail(`Cannot write to file ${path}`, err);
|
|
111
|
+
}
|
|
112
|
+
finally {
|
|
113
|
+
if (fHandle) {
|
|
114
|
+
await fHandle.sync();
|
|
115
|
+
await fHandle.close();
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
async append(path, data, encoding) {
|
|
120
|
+
await (0, promises_1.appendFile)(path, data, encoding);
|
|
121
|
+
}
|
|
122
|
+
writeStream(path, rStream, encoding) {
|
|
123
|
+
const stream = (0, fs_1.createWriteStream)(this.resolvePath(path), {
|
|
124
|
+
encoding: (typeof rStream === 'string' ? rStream : encoding) ?? 'binary',
|
|
125
|
+
});
|
|
126
|
+
if (rStream instanceof fs_1.ReadStream) {
|
|
127
|
+
rStream.pipe(stream);
|
|
128
|
+
}
|
|
129
|
+
return Promise.resolve(stream);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Checks if file existst
|
|
133
|
+
* @param path - path to check
|
|
134
|
+
*/
|
|
135
|
+
async exists(path) {
|
|
136
|
+
try {
|
|
137
|
+
await (0, promises_1.access)(this.resolvePath(path), fs_1.constants.F_OK);
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
catch {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
async dirExists(path) {
|
|
145
|
+
return this.exists(this.resolvePath(path));
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Copy file or dir to another location
|
|
149
|
+
* @param path - src path
|
|
150
|
+
* @param dest - dest path
|
|
151
|
+
*/
|
|
152
|
+
async copy(path, dest, dstFs) {
|
|
153
|
+
const sPath = this.resolvePath(path);
|
|
154
|
+
const exists = await this.exists(path);
|
|
155
|
+
if (!exists) {
|
|
156
|
+
throw new exceptions_1.IOFail(`File ${path} not exists`);
|
|
157
|
+
}
|
|
158
|
+
if (dstFs) {
|
|
159
|
+
await dstFs.upload(sPath, dest);
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
const dPath = this.resolvePath(dest);
|
|
163
|
+
await (0, promises_2.cp)(sPath, dPath, {
|
|
164
|
+
recursive: true,
|
|
165
|
+
force: true,
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Copy file to another location and deletes src file
|
|
171
|
+
*/
|
|
172
|
+
async move(oldPath, newPath, dstFs) {
|
|
173
|
+
const oPath = this.resolvePath(oldPath);
|
|
174
|
+
if (dstFs) {
|
|
175
|
+
await dstFs.upload(oPath, newPath);
|
|
176
|
+
await this.rm(oldPath);
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
const nPath = this.resolvePath(newPath);
|
|
180
|
+
await (0, promises_1.rename)(oPath, nPath);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Change name of a file
|
|
185
|
+
*/
|
|
186
|
+
async rename(oldPath, newPath) {
|
|
187
|
+
await (0, promises_1.rename)(this.resolvePath(oldPath), this.resolvePath(newPath));
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
*
|
|
191
|
+
* Deletes file OR
|
|
192
|
+
* Deletes dir recursively & all contents inside
|
|
193
|
+
*
|
|
194
|
+
* @param path - dir to remove
|
|
195
|
+
*/
|
|
196
|
+
async rm(path) {
|
|
197
|
+
await (0, promises_1.rm)(this.resolvePath(path), { recursive: true, force: true, maxRetries: 3, retryDelay: 1000 });
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
*
|
|
201
|
+
* Creates directory, recursively
|
|
202
|
+
*
|
|
203
|
+
* @param path - directory to create
|
|
204
|
+
*/
|
|
205
|
+
async mkdir(path) {
|
|
206
|
+
await (0, promises_1.mkdir)(this.resolvePath(path), { recursive: true });
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Returns file statistics, not all fields may be accesible
|
|
210
|
+
*/
|
|
211
|
+
async stat(path) {
|
|
212
|
+
const result = await (0, promises_1.stat)(this.resolvePath(path));
|
|
213
|
+
return {
|
|
214
|
+
IsDirectory: result.isDirectory(),
|
|
215
|
+
IsFile: result.isFile(),
|
|
216
|
+
CreationTime: luxon_1.DateTime.fromJSDate(result.ctime),
|
|
217
|
+
ModifiedTime: luxon_1.DateTime.fromJSDate(result.mtime),
|
|
218
|
+
AccessTime: luxon_1.DateTime.fromJSDate(result.atime),
|
|
219
|
+
Size: result.size,
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
tmppath() {
|
|
223
|
+
return (0, path_1.join)(this.Options.basePath, super.tmpname());
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* List content of directory
|
|
227
|
+
*
|
|
228
|
+
* @param path - path to directory
|
|
229
|
+
*/
|
|
230
|
+
async list(path) {
|
|
231
|
+
return await (0, promises_1.readdir)(this.resolvePath(path));
|
|
232
|
+
}
|
|
233
|
+
async unzip(path, destPath, dstFs) {
|
|
234
|
+
const dFs = dstFs ?? this;
|
|
235
|
+
const dst = dFs.resolvePath(destPath ?? dFs.tmpname());
|
|
236
|
+
return new Promise((resolve, reject) => {
|
|
237
|
+
(0, fs_1.createReadStream)(this.resolvePath(path)).pipe(unzipper_1.default
|
|
238
|
+
.Extract({
|
|
239
|
+
path: dst,
|
|
240
|
+
})
|
|
241
|
+
.on('close', resolve)
|
|
242
|
+
.on('error', reject));
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
async isDir(path) {
|
|
246
|
+
try {
|
|
247
|
+
const pStat = await this.stat(path);
|
|
248
|
+
return pStat.IsDirectory;
|
|
249
|
+
}
|
|
250
|
+
catch {
|
|
251
|
+
return false;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
async zip(path, dstFs, dstFile) {
|
|
255
|
+
const paths = (0, util_1.toArray)(path);
|
|
256
|
+
const fs = dstFs ?? (await di_1.DI.resolve('__file_provider__', ['fs-temp']));
|
|
257
|
+
const outFile = dstFile ?? `${fs.tmpname()}.zip`;
|
|
258
|
+
const wStream = await fs.writeStream(outFile);
|
|
259
|
+
const archive = (0, archiver_1.default)('zip');
|
|
260
|
+
// pipe archive data to the file
|
|
261
|
+
archive.pipe(wStream);
|
|
262
|
+
for (const p of paths.map((p) => this.resolvePath(p))) {
|
|
263
|
+
if (await this.isDir(p)) {
|
|
264
|
+
archive.directory(p, false);
|
|
265
|
+
continue;
|
|
266
|
+
}
|
|
267
|
+
archive.file(p, { name: (0, path_1.basename)(p) });
|
|
268
|
+
}
|
|
269
|
+
return new Promise((resolve, reject) => {
|
|
270
|
+
archive.on('warning', (err) => {
|
|
271
|
+
if (err.code === 'ENOENT') {
|
|
272
|
+
this.Logger.error(err, `File not found ( archiving file ), reason: ${err.message})`);
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
reject(new exceptions_1.IOFail('Archiving error', err));
|
|
276
|
+
});
|
|
277
|
+
archive.on('error', (err) => {
|
|
278
|
+
reject(new exceptions_1.IOFail('Archiving error', err));
|
|
279
|
+
});
|
|
280
|
+
archive.on('entry', (entry) => {
|
|
281
|
+
this.Logger.trace(`Archiving file ${entry.name}, size: ${entry.stats?.size} into ${outFile}, fs: ${fs.Name}`);
|
|
282
|
+
});
|
|
283
|
+
wStream.on('close', () => {
|
|
284
|
+
const result = {
|
|
285
|
+
fs,
|
|
286
|
+
asFilePath: () => {
|
|
287
|
+
return outFile;
|
|
288
|
+
},
|
|
289
|
+
asStream: (encoding) => {
|
|
290
|
+
return (0, fs_1.createReadStream)(outFile, {
|
|
291
|
+
encoding: encoding ?? 'binary',
|
|
292
|
+
});
|
|
293
|
+
},
|
|
294
|
+
asBase64: () => {
|
|
295
|
+
return (0, fs_1.readFileSync)(outFile, { encoding: 'base64' });
|
|
296
|
+
},
|
|
297
|
+
unlink: async () => {
|
|
298
|
+
return await fs.rm(outFile);
|
|
299
|
+
},
|
|
300
|
+
};
|
|
301
|
+
resolve(result);
|
|
302
|
+
});
|
|
303
|
+
archive.finalize();
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
resolvePath(path) {
|
|
307
|
+
if (!this.Options.basePath || path.startsWith(this.Options.basePath))
|
|
308
|
+
return path;
|
|
309
|
+
return (0, path_1.join)(this.Options.basePath, path);
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
exports.fsNative = fsNative;
|
|
313
|
+
__decorate([
|
|
314
|
+
(0, log_common_1.Logger)('fs'),
|
|
315
|
+
__metadata("design:type", log_common_1.Log)
|
|
316
|
+
], fsNative.prototype, "Logger", void 0);
|
|
317
|
+
exports.fsNative = fsNative = __decorate([
|
|
318
|
+
(0, di_1.Injectable)('fs'),
|
|
319
|
+
(0, di_1.PerInstanceCheck)(),
|
|
320
|
+
__metadata("design:paramtypes", [Object])
|
|
321
|
+
], fsNative);
|
|
279
322
|
//# sourceMappingURL=local-provider.js.map
|