@spinajs/fs 2.0.38 → 2.0.45

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.
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const path_1 = require("path");
4
+ function dir(path) {
5
+ return (0, path_1.resolve)((0, path_1.normalize)((0, path_1.join)(__dirname, path)));
6
+ }
7
+ module.exports = {
8
+ fs: {
9
+ defaultProvider: 'fs-local',
10
+ providers: [
11
+ {
12
+ service: 'fsNative',
13
+ name: 'fs-local',
14
+ basePath: dir('./../fs/files'),
15
+ },
16
+ /**
17
+ * provide temporary fs access
18
+ */
19
+ {
20
+ service: 'fsNative',
21
+ name: 'fs-temp',
22
+ basePath: dir('./../fs/temp'),
23
+ },
24
+ ],
25
+ },
26
+ };
27
+ //# sourceMappingURL=fs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fs.js","sourceRoot":"","sources":["../../src/config/fs.ts"],"names":[],"mappings":";;AAAA,+BAAgD;AAEhD,SAAS,GAAG,CAAC,IAAY;IACvB,OAAO,IAAA,cAAO,EAAC,IAAA,gBAAS,EAAC,IAAA,WAAI,EAAC,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;AACnD,CAAC;AAED,MAAM,CAAC,OAAO,GAAG;IACf,EAAE,EAAE;QACF,eAAe,EAAE,UAAU;QAC3B,SAAS,EAAE;YACT;gBACE,OAAO,EAAE,UAAU;gBACnB,IAAI,EAAE,UAAU;gBAChB,QAAQ,EAAE,GAAG,CAAC,eAAe,CAAC;aAC/B;YACD;;eAEG;YACH;gBACE,OAAO,EAAE,UAAU;gBACnB,IAAI,EAAE,SAAS;gBACf,QAAQ,EAAE,GAAG,CAAC,cAAc,CAAC;aAC9B;SACF;KACF;CACF,CAAC"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import { Bootstrapper } from '@spinajs/di';
2
+ export * from './interfaces';
3
+ export * from './local-provider';
4
+ export declare class FsBootsrapper extends Bootstrapper {
5
+ bootstrap(): void;
6
+ }
package/lib/index.js ADDED
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
14
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
15
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
16
+ 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;
17
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
18
+ };
19
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
20
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.FsBootsrapper = void 0;
24
+ const configuration_1 = require("@spinajs/configuration");
25
+ const di_1 = require("@spinajs/di");
26
+ const interfaces_1 = require("./interfaces");
27
+ __exportStar(require("./interfaces"), exports);
28
+ __exportStar(require("./local-provider"), exports);
29
+ let FsBootsrapper = class FsBootsrapper extends di_1.Bootstrapper {
30
+ bootstrap() {
31
+ di_1.DI.register(async (container, name) => {
32
+ const cfg = container.get(configuration_1.Configuration).get('fs');
33
+ const defaultProvider = cfg.defaultProvider;
34
+ if (!defaultProvider) {
35
+ throw new configuration_1.InvalidConfiguration('fs default provider is not set. Please set default file provider ');
36
+ }
37
+ const cProvider = cfg.providers.find((x) => x.name === (name !== null && name !== void 0 ? name : defaultProvider));
38
+ const rProviders = di_1.DI.RootContainer.Registry.getTypes(interfaces_1.fs);
39
+ const provider = await di_1.DI.resolve(rProviders.find((x) => x.name === cProvider.service), [cProvider]);
40
+ return provider;
41
+ }).as('__file_provider__');
42
+ }
43
+ };
44
+ FsBootsrapper = __decorate([
45
+ (0, di_1.Injectable)(di_1.Bootstrapper)
46
+ ], FsBootsrapper);
47
+ exports.FsBootsrapper = FsBootsrapper;
48
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAA6E;AAC7E,oCAAuE;AACvE,6CAAoD;AAEpD,+CAA6B;AAC7B,mDAAiC;AAGjC,IAAa,aAAa,GAA1B,MAAa,aAAc,SAAQ,iBAAY;IACtC,SAAS;QACd,OAAE,CAAC,QAAQ,CAAC,KAAK,EAAE,SAAqB,EAAE,IAAa,EAAE,EAAE;YACzD,MAAM,GAAG,GAAG,SAAS,CAAC,GAAG,CAAC,6BAAa,CAAC,CAAC,GAAG,CAAmB,IAAI,CAAC,CAAC;YACrE,MAAM,eAAe,GAAG,GAAG,CAAC,eAAe,CAAC;YAE5C,IAAI,CAAC,eAAe,EAAE;gBACpB,MAAM,IAAI,oCAAoB,CAAC,mEAAmE,CAAC,CAAC;aACrG;YAED,MAAM,SAAS,GAAG,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,eAAe,CAAC,CAAC,CAAC;YAClF,MAAM,UAAU,GAAG,OAAE,CAAC,aAAa,CAAC,QAAQ,CAAC,QAAQ,CAAC,eAAE,CAAC,CAAC;YAC1D,MAAM,QAAQ,GAAG,MAAM,OAAE,CAAC,OAAO,CAC/B,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,SAAS,CAAC,OAAO,CAAC,EACpD,CAAC,SAAS,CAAC,CACZ,CAAC;YAEF,OAAO,QAAQ,CAAC;QAClB,CAAC,CAAC,CAAC,EAAE,CAAC,mBAAmB,CAAC,CAAC;IAC7B,CAAC;CACF,CAAA;AApBY,aAAa;IADzB,IAAA,eAAU,EAAC,iBAAY,CAAC;GACZ,aAAa,CAoBzB;AApBY,sCAAa"}
@@ -0,0 +1,60 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ /// <reference types="node" />
4
+ import { AsyncService, IInstanceCheck, IMappableService } from '@spinajs/di';
5
+ import { ReadStream, WriteStream } from 'fs';
6
+ import { DateTime } from 'luxon';
7
+ import { PassThrough } from 'stream';
8
+ export interface IProviderConfiguration {
9
+ name: string;
10
+ service: string;
11
+ }
12
+ export interface IFsConfiguration {
13
+ defaultProvider: string;
14
+ providers: IProviderConfiguration[];
15
+ }
16
+ export interface IStat {
17
+ IsDirectory?: boolean;
18
+ IsFile?: boolean;
19
+ Size?: number;
20
+ AccessTime?: DateTime;
21
+ ModifiedTime?: DateTime;
22
+ CreationTime?: DateTime;
23
+ AdditionalData?: unknown;
24
+ }
25
+ export interface IZipResult {
26
+ asFilePath(): string;
27
+ asStream(): ReadStream;
28
+ asBase64(): string;
29
+ }
30
+ export declare abstract class fs extends AsyncService implements IMappableService, IInstanceCheck {
31
+ get ServiceName(): string;
32
+ __checkInstance__(creationOptions: any): boolean;
33
+ abstract Name: string;
34
+ abstract download(path: string): Promise<string>;
35
+ abstract read(path: string, encoding: BufferEncoding): Promise<string | Buffer>;
36
+ abstract readStream(path: string, encoding?: BufferEncoding): Promise<ReadStream>;
37
+ abstract write(path: string, data: string | Buffer, encoding?: BufferEncoding): Promise<void>;
38
+ abstract writeStream(path: string, encoding?: BufferEncoding): Promise<WriteStream | PassThrough>;
39
+ abstract exists(path: string): Promise<boolean>;
40
+ abstract dirExists(path: string): Promise<boolean>;
41
+ abstract copy(path: string, dest: string): Promise<void>;
42
+ abstract move(oldPath: string, newPath: string): Promise<void>;
43
+ abstract rename(oldPath: string, newPath: string): Promise<void>;
44
+ abstract unlink(path: string, downloaded?: boolean): Promise<void>;
45
+ abstract rm(path: string): Promise<void>;
46
+ abstract mkdir(path: string): Promise<void>;
47
+ abstract stat(path: string): Promise<IStat>;
48
+ abstract list(path: string): Promise<string[]>;
49
+ abstract tmppath(): string;
50
+ abstract append(path: string, data: string | Buffer, encoding?: BufferEncoding): Promise<void>;
51
+ /**
52
+ *
53
+ * Compress specified file or dir in provided path. If
54
+ * Dir is compressed recursively
55
+ *
56
+ * @param path - path to zip
57
+ */
58
+ abstract zip(path: string): Promise<IZipResult>;
59
+ tmpname(): string;
60
+ }
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fs = void 0;
4
+ /* eslint-disable security/detect-non-literal-fs-filename */
5
+ const di_1 = require("@spinajs/di");
6
+ const uuid_1 = require("uuid");
7
+ class fs extends di_1.AsyncService {
8
+ get ServiceName() {
9
+ return this.Name;
10
+ }
11
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
12
+ __checkInstance__(creationOptions) {
13
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
14
+ return this.Name === creationOptions[0].name;
15
+ }
16
+ tmpname() {
17
+ return (0, uuid_1.v4)();
18
+ }
19
+ }
20
+ exports.fs = fs;
21
+ //# sourceMappingURL=interfaces.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":";;;AAAA,4DAA4D;AAC5D,oCAA6E;AAI7E,+BAAoC;AA2BpC,MAAsB,EAAG,SAAQ,iBAAY;IAC3C,IAAW,WAAW;QACpB,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED,8DAA8D;IACvD,iBAAiB,CAAC,eAAoB;QAC3C,sEAAsE;QACtE,OAAO,IAAI,CAAC,IAAI,KAAK,eAAe,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAC/C,CAAC;IA6BM,OAAO;QACZ,OAAO,IAAA,SAAM,GAAE,CAAC;IAClB,CAAC;CACF;AAzCD,gBAyCC"}
@@ -0,0 +1,101 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import { fs, IStat, IZipResult } from './interfaces';
4
+ import { ILog } from '@spinajs/log';
5
+ export interface IFsLocalOptions {
6
+ basePath: string;
7
+ name: string;
8
+ }
9
+ /**
10
+ * Abstract layer for file operations.
11
+ * Basic implementation is just wrapper for native node fs functions
12
+ *
13
+ * It allows to wrap other libs eg. aws s3, ftp
14
+ * and inject it into code without changing logic that use them.
15
+ *
16
+ * TODO: map errors to some kind of common errors shared with other implementations
17
+ */
18
+ export declare class fsNative extends fs {
19
+ Options: IFsLocalOptions;
20
+ protected Logger: ILog;
21
+ /**
22
+ * Name of provider. We can have multiple providers of the same type but with different options.
23
+ * Also used in InjectService decorator for mapping
24
+ */
25
+ get Name(): string;
26
+ constructor(Options: IFsLocalOptions);
27
+ resolve(): Promise<void>;
28
+ /**
29
+ *
30
+ * Tries to download file to local filesystem, then returns local filesystem path.
31
+ * Native implementation simply returns local path and does nothing.
32
+ *
33
+ * @param path - file to download
34
+ */
35
+ download(path: string): Promise<string>;
36
+ /**
37
+ * read all content of file
38
+ */
39
+ read(path: string, encoding?: BufferEncoding): Promise<string | Buffer>;
40
+ readStream(path: string, encoding?: BufferEncoding): Promise<import("fs").ReadStream>;
41
+ /**
42
+ * Write to file string or buffer
43
+ */
44
+ write(path: string, data: string | Buffer, encoding: BufferEncoding): Promise<void>;
45
+ append(path: string, data: string | Buffer, encoding?: BufferEncoding): Promise<void>;
46
+ writeStream(path: string, encoding?: BufferEncoding): Promise<import("fs").WriteStream>;
47
+ /**
48
+ * Checks if file existst
49
+ * @param path - path to check
50
+ */
51
+ exists(path: string): Promise<boolean>;
52
+ dirExists(path: string): Promise<boolean>;
53
+ /**
54
+ * Copy file to another location
55
+ * @param path - src path
56
+ * @param dest - dest path
57
+ */
58
+ copy(path: string, dest: string): Promise<void>;
59
+ /**
60
+ * Copy file to another location and deletes src file
61
+ */
62
+ move(oldPath: string, newPath: string): Promise<void>;
63
+ /**
64
+ * Change name of a file
65
+ */
66
+ rename(oldPath: string, newPath: string): Promise<void>;
67
+ /**
68
+ * Deletes file permanently
69
+ *
70
+ * @param path - path to file that will be deleted
71
+ * @param onlyTemp - remote filesystems need to download file before, if so, calling unlink with this flag removes only local temp file after we finished processing
72
+ */
73
+ unlink(path: string, onlyTemp?: boolean): Promise<void>;
74
+ /**
75
+ *
76
+ * Deletes dir recursively & all contents inside
77
+ *
78
+ * @param path - dir to remove
79
+ */
80
+ rm(path: string): Promise<void>;
81
+ /**
82
+ *
83
+ * Creates directory, recursively
84
+ *
85
+ * @param path - directory to create
86
+ */
87
+ mkdir(path: string): Promise<void>;
88
+ /**
89
+ * Returns file statistics, not all fields may be accesible
90
+ */
91
+ stat(path: string): Promise<IStat>;
92
+ tmppath(): string;
93
+ /**
94
+ * List content of directory
95
+ *
96
+ * @param path - path to directory
97
+ */
98
+ list(path: string): Promise<string[]>;
99
+ zip(path: string, zName?: string): Promise<IZipResult>;
100
+ protected resolvePath(path: string): string;
101
+ }
@@ -0,0 +1,257 @@
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_1 = require("./interfaces");
23
+ const path_1 = require("path");
24
+ const log_1 = require("@spinajs/log");
25
+ const archiver_1 = __importDefault(require("archiver"));
26
+ /**
27
+ * Abstract layer for file operations.
28
+ * Basic implementation is just wrapper for native node fs functions
29
+ *
30
+ * It allows to wrap other libs eg. aws s3, ftp
31
+ * and inject it into code without changing logic that use them.
32
+ *
33
+ * TODO: map errors to some kind of common errors shared with other implementations
34
+ */
35
+ let fsNative = class fsNative extends interfaces_1.fs {
36
+ constructor(Options) {
37
+ super();
38
+ this.Options = Options;
39
+ }
40
+ /**
41
+ * Name of provider. We can have multiple providers of the same type but with different options.
42
+ * Also used in InjectService decorator for mapping
43
+ */
44
+ get Name() {
45
+ return this.Options.name;
46
+ }
47
+ async resolve() {
48
+ // yup, exceptions as conditional execution path is bad :)
49
+ try {
50
+ await (0, promises_1.access)(this.Options.basePath, fs_1.constants.F_OK);
51
+ }
52
+ catch (_a) {
53
+ this.Logger.warn(`Base path ${this.Options.basePath} for file provider ${this.Options.name} not exists, trying to create base folder`);
54
+ await (0, promises_1.mkdir)(this.Options.basePath, { recursive: true });
55
+ this.Logger.success(`Base path ${this.Options.basePath} created`);
56
+ }
57
+ }
58
+ /**
59
+ *
60
+ * Tries to download file to local filesystem, then returns local filesystem path.
61
+ * Native implementation simply returns local path and does nothing.
62
+ *
63
+ * @param path - file to download
64
+ */
65
+ async download(path) {
66
+ const exists = await this.exists(this.resolvePath(path));
67
+ if (!exists) {
68
+ throw new exceptions_1.IOFail(`file ${path} does not exists`);
69
+ }
70
+ return this.resolvePath(path);
71
+ }
72
+ /**
73
+ * read all content of file
74
+ */
75
+ async read(path, encoding) {
76
+ return new Promise((resolve, reject) => {
77
+ (0, fs_1.readFile)(this.resolvePath(path), { encoding: encoding !== null && encoding !== void 0 ? encoding : 'binary' }, (err, data) => {
78
+ if (err) {
79
+ reject(err);
80
+ }
81
+ else {
82
+ resolve(data);
83
+ }
84
+ });
85
+ });
86
+ }
87
+ readStream(path, encoding) {
88
+ return Promise.resolve((0, fs_1.createReadStream)(this.resolvePath(path), { encoding: encoding !== null && encoding !== void 0 ? encoding : 'binary' }));
89
+ }
90
+ /**
91
+ * Write to file string or buffer
92
+ */
93
+ async write(path, data, encoding) {
94
+ const fDesc = await (0, promises_1.open)(this.resolvePath(path), 'w');
95
+ return await fDesc.writeFile(data, { encoding });
96
+ }
97
+ async append(path, data, encoding) {
98
+ await (0, promises_1.appendFile)(path, data, encoding);
99
+ }
100
+ writeStream(path, encoding) {
101
+ return Promise.resolve((0, fs_1.createWriteStream)(this.resolvePath(path), { encoding: encoding !== null && encoding !== void 0 ? encoding : 'binary' }));
102
+ }
103
+ /**
104
+ * Checks if file existst
105
+ * @param path - path to check
106
+ */
107
+ async exists(path) {
108
+ try {
109
+ await (0, promises_1.access)(this.resolvePath(path), fs_1.constants.F_OK);
110
+ return true;
111
+ }
112
+ catch (_a) {
113
+ return false;
114
+ }
115
+ }
116
+ async dirExists(path) {
117
+ return this.exists(this.resolvePath(path));
118
+ }
119
+ /**
120
+ * Copy file to another location
121
+ * @param path - src path
122
+ * @param dest - dest path
123
+ */
124
+ async copy(path, dest) {
125
+ await (0, promises_1.copyFile)(this.resolvePath(path), this.resolvePath(dest));
126
+ }
127
+ /**
128
+ * Copy file to another location and deletes src file
129
+ */
130
+ async move(oldPath, newPath) {
131
+ const oPath = this.resolvePath(oldPath);
132
+ const nPath = this.resolvePath(newPath);
133
+ try {
134
+ await (0, promises_1.rename)(oPath, nPath);
135
+ }
136
+ catch (err) {
137
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
138
+ if (err.code === 'EXDEV') {
139
+ await (0, promises_1.copyFile)(oPath, nPath);
140
+ await (0, promises_1.unlink)(oPath);
141
+ }
142
+ else {
143
+ throw err;
144
+ }
145
+ }
146
+ }
147
+ /**
148
+ * Change name of a file
149
+ */
150
+ async rename(oldPath, newPath) {
151
+ await (0, promises_1.rename)(this.resolvePath(oldPath), this.resolvePath(newPath));
152
+ }
153
+ /**
154
+ * Deletes file permanently
155
+ *
156
+ * @param path - path to file that will be deleted
157
+ * @param onlyTemp - remote filesystems need to download file before, if so, calling unlink with this flag removes only local temp file after we finished processing
158
+ */
159
+ async unlink(path, onlyTemp) {
160
+ // local fs returns only local path to file, we dont want to delete it
161
+ if (onlyTemp) {
162
+ return;
163
+ }
164
+ await (0, promises_1.unlink)(this.resolvePath(path));
165
+ }
166
+ /**
167
+ *
168
+ * Deletes dir recursively & all contents inside
169
+ *
170
+ * @param path - dir to remove
171
+ */
172
+ async rm(path) {
173
+ await (0, promises_1.rm)(this.resolvePath(path), { recursive: true, force: true, maxRetries: 3, retryDelay: 1000 });
174
+ }
175
+ /**
176
+ *
177
+ * Creates directory, recursively
178
+ *
179
+ * @param path - directory to create
180
+ */
181
+ async mkdir(path) {
182
+ await (0, promises_1.mkdir)(this.resolvePath(path), { recursive: true });
183
+ }
184
+ /**
185
+ * Returns file statistics, not all fields may be accesible
186
+ */
187
+ async stat(path) {
188
+ const result = await (0, promises_1.stat)(this.resolvePath(path));
189
+ return {
190
+ IsDirectory: result.isDirectory(),
191
+ IsFile: result.isFile(),
192
+ CreationTime: luxon_1.DateTime.fromJSDate(result.ctime),
193
+ ModifiedTime: luxon_1.DateTime.fromJSDate(result.mtime),
194
+ AccessTime: luxon_1.DateTime.fromJSDate(result.atime),
195
+ Size: result.size,
196
+ };
197
+ }
198
+ tmppath() {
199
+ return (0, path_1.join)(this.Options.basePath, super.tmpname());
200
+ }
201
+ /**
202
+ * List content of directory
203
+ *
204
+ * @param path - path to directory
205
+ */
206
+ async list(path) {
207
+ return await (0, promises_1.readdir)(this.resolvePath(path));
208
+ }
209
+ async zip(path, zName) {
210
+ const outFile = this.resolvePath(this.tmpname() + '.zip');
211
+ const output = (0, fs_1.createWriteStream)(outFile);
212
+ const pStat = await this.stat(path);
213
+ const fPath = this.resolvePath(path);
214
+ const archive = (0, archiver_1.default)('zip', {
215
+ zlib: { level: 9 }, // Sets the compression level.
216
+ });
217
+ // pipe archive data to the file
218
+ archive.pipe(output);
219
+ if (pStat.IsDirectory) {
220
+ archive.directory(fPath, false);
221
+ }
222
+ else {
223
+ archive.file(fPath, { name: zName !== null && zName !== void 0 ? zName : (0, path_1.basename)(fPath) });
224
+ }
225
+ await archive.finalize();
226
+ return {
227
+ asFilePath: () => {
228
+ return outFile;
229
+ },
230
+ asStream: (encoding) => {
231
+ return (0, fs_1.createReadStream)(outFile, {
232
+ encoding: encoding !== null && encoding !== void 0 ? encoding : 'binary',
233
+ });
234
+ },
235
+ asBase64: () => {
236
+ return (0, fs_1.readFileSync)(outFile, { encoding: 'base64' });
237
+ },
238
+ };
239
+ }
240
+ resolvePath(path) {
241
+ if (path.startsWith(this.Options.basePath)) {
242
+ return path;
243
+ }
244
+ return (0, path_1.join)(this.Options.basePath, path);
245
+ }
246
+ };
247
+ __decorate([
248
+ (0, log_1.Logger)('fs'),
249
+ __metadata("design:type", Object)
250
+ ], fsNative.prototype, "Logger", void 0);
251
+ fsNative = __decorate([
252
+ (0, di_1.Injectable)('fs'),
253
+ (0, di_1.PerInstanceCheck)(),
254
+ __metadata("design:paramtypes", [Object])
255
+ ], fsNative);
256
+ exports.fsNative = fsNative;
257
+ //# source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AAI,CAAC,KAAK,EAAE,EAAE,IAAI,EAAE,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,IAAA,eAAQ,EAAC,KAAK,CAAC,EAAE,CAAC,CAAC;SACzD;QAED,MAAM,OAAO,CAAC,QAAQ,EAAE,CAAC;QAEzB,OAAO;YACL,UAAU,EAAE,GAAG,EAAE;gBACf,OAAO,OAAO,CAAC;YACjB,CAAC;YACD,QAAQ,EAAE,CAAC,QAAyB,EAAE,EAAE;gBACtC,OAAO,IAAA,qBAAgB,EAAC,OAAO,EAAE;oBAC/B,QAAQ,EAAE,QAAQ,aAAR,QAAQ,cAAR,QAAQ,GAAI,QAAQ;iBAC/B,CAAC,CAAC;YACL,CAAC;YACD,QAAQ,EAAE,GAAG,EAAE;gBACb,OAAO,IAAA,iBAAY,EAAC,OAAO,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAAC;YACvD,CAAC;SACF,CAAC;IACJ,CAAC;IAES,WAAW,CAAC,IAAY;QAChC,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;YAC1C,OAAO,IAAI,CAAC;SACb;QAED,OAAO,IAAA,WAAI,EAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IAC3C,CAAC;CACF,CAAA;AA7OC;IADC,IAAA,YAAM,EAAC,IAAI,CAAC;;wCACU;AAFZ,QAAQ;IAFpB,IAAA,eAAU,EAAC,IAAI,CAAC;IAChB,IAAA,qBAAgB,GAAE;;GACN,QAAQ,CA+OpB;AA/OY,4BAAQ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spinajs/fs",
3
- "version": "2.0.38",
3
+ "version": "2.0.45",
4
4
  "description": "wrapper for file operations",
5
5
  "main": "lib/index.js",
6
6
  "private": false,
@@ -38,12 +38,16 @@
38
38
  "url": "https://github.com/spinajs/exceptions/issues"
39
39
  },
40
40
  "homepage": "https://github.com/spinajs/exceptions#readme",
41
- "gitHead": "5ea5440ee9db49595f531592ebdbc6d69f457082",
41
+ "gitHead": "3aa423c570eae952dc79fe6a4704c3d2ccc178be",
42
42
  "dependencies": {
43
+ "archiver": "^5.3.1",
43
44
  "lodash": "^4.17.21",
44
- "luxon": "^3.0.0"
45
+ "luxon": "^3.2.1",
46
+ "uuid": "^8.3.2"
45
47
  },
46
48
  "devDependencies": {
47
- "@types/luxon": "^3.0.1"
49
+ "@types/archiver": "^5.3.1",
50
+ "@types/luxon": "^3.0.1",
51
+ "@types/uuid": "^8.3.3"
48
52
  }
49
53
  }
@@ -1,85 +0,0 @@
1
- /**
2
- * Base class of all exceptions in framework
3
- */
4
- export declare class Exception extends Error {
5
- inner?: Error;
6
- /**
7
- * Constructs new exception with message
8
- *
9
- * @param message - error message
10
- * @param inner - inner exception ( eg. original couse of error )
11
- */
12
- constructor(message?: string, inner?: Error);
13
- }
14
- /**
15
- * Exception thrown when functionality is not supported
16
- */
17
- export declare class NotSupported extends Exception {
18
- }
19
- /**
20
- * Exception thrown when argument passed to function is invalid eg. out of range
21
- */
22
- export declare class InvalidArgument extends Exception {
23
- }
24
- /**
25
- * Exception thrown when config option is invalidl eg. missing or in invalid format
26
- */
27
- export declare class InvalidOption extends Exception {
28
- }
29
- /**
30
- * The exception that is thrown when a method call is invalid for the object's current state.
31
- */
32
- export declare class InvalidOperation extends Exception {
33
- }
34
- /**
35
- * Exception is thrown when authentication fails eg. user credentials are invalid
36
- */
37
- export declare class AuthenticationFailed extends Exception {
38
- }
39
- /**
40
- * Exception is thrown when request data are invalid
41
- */
42
- export declare class BadRequest extends Exception {
43
- }
44
- /**
45
- * Exception indicating that an access to resource by a client has been forbidden by the server
46
- * HTTP 403 - Forbidden
47
- */
48
- export declare class Forbidden extends Exception {
49
- }
50
- /**
51
- * Exception thrown when there was error with IO operations ie. not accessible file
52
- */
53
- export declare class IOFail extends Exception {
54
- }
55
- /**
56
- * The exception that is thrown when resource is not found eg. model in database or missing file
57
- */
58
- export declare class ResourceNotFound extends Exception {
59
- }
60
- /**
61
- * The exception that is thrown when method is not implemented
62
- */
63
- export declare class MethodNotImplemented extends Exception {
64
- }
65
- /**
66
- * The exception that is thrown when strange things happends in server eg. generic server error
67
- */
68
- export declare class UnexpectedServerError extends Exception {
69
- }
70
- /**
71
- * Exception occurs when resource is duplicated eg. unique constraint failed in db
72
- */
73
- export declare class ResourceDuplicated extends Exception {
74
- }
75
- /**
76
- * The exception that is thrown when JSON entity is checked against schema and is invalid
77
- */
78
- export declare class JsonValidationFailed extends Exception {
79
- }
80
- /**
81
- * The exception that is thrown if app not supports requestes `Accept` header eg. if client wants
82
- * html response but server can send only json.
83
- */
84
- export declare class ExpectedResponseUnacceptable extends Exception {
85
- }
@@ -1,106 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ExpectedResponseUnacceptable = exports.JsonValidationFailed = exports.ResourceDuplicated = exports.UnexpectedServerError = exports.MethodNotImplemented = exports.ResourceNotFound = exports.IOFail = exports.Forbidden = exports.BadRequest = exports.AuthenticationFailed = exports.InvalidOperation = exports.InvalidOption = exports.InvalidArgument = exports.NotSupported = exports.Exception = void 0;
4
- /**
5
- * Base class of all exceptions in framework
6
- */
7
- class Exception extends Error {
8
- /**
9
- * Constructs new exception with message
10
- *
11
- * @param message - error message
12
- * @param inner - inner exception ( eg. original couse of error )
13
- */
14
- constructor(message, inner) {
15
- super(message);
16
- this.inner = inner;
17
- }
18
- }
19
- exports.Exception = Exception;
20
- /**
21
- * Exception thrown when functionality is not supported
22
- */
23
- class NotSupported extends Exception {
24
- }
25
- exports.NotSupported = NotSupported;
26
- /**
27
- * Exception thrown when argument passed to function is invalid eg. out of range
28
- */
29
- class InvalidArgument extends Exception {
30
- }
31
- exports.InvalidArgument = InvalidArgument;
32
- /**
33
- * Exception thrown when config option is invalidl eg. missing or in invalid format
34
- */
35
- class InvalidOption extends Exception {
36
- }
37
- exports.InvalidOption = InvalidOption;
38
- /**
39
- * The exception that is thrown when a method call is invalid for the object's current state.
40
- */
41
- class InvalidOperation extends Exception {
42
- }
43
- exports.InvalidOperation = InvalidOperation;
44
- /**
45
- * Exception is thrown when authentication fails eg. user credentials are invalid
46
- */
47
- class AuthenticationFailed extends Exception {
48
- }
49
- exports.AuthenticationFailed = AuthenticationFailed;
50
- /**
51
- * Exception is thrown when request data are invalid
52
- */
53
- class BadRequest extends Exception {
54
- }
55
- exports.BadRequest = BadRequest;
56
- /**
57
- * Exception indicating that an access to resource by a client has been forbidden by the server
58
- * HTTP 403 - Forbidden
59
- */
60
- class Forbidden extends Exception {
61
- }
62
- exports.Forbidden = Forbidden;
63
- /**
64
- * Exception thrown when there was error with IO operations ie. not accessible file
65
- */
66
- class IOFail extends Exception {
67
- }
68
- exports.IOFail = IOFail;
69
- /**
70
- * The exception that is thrown when resource is not found eg. model in database or missing file
71
- */
72
- class ResourceNotFound extends Exception {
73
- }
74
- exports.ResourceNotFound = ResourceNotFound;
75
- /**
76
- * The exception that is thrown when method is not implemented
77
- */
78
- class MethodNotImplemented extends Exception {
79
- }
80
- exports.MethodNotImplemented = MethodNotImplemented;
81
- /**
82
- * The exception that is thrown when strange things happends in server eg. generic server error
83
- */
84
- class UnexpectedServerError extends Exception {
85
- }
86
- exports.UnexpectedServerError = UnexpectedServerError;
87
- /**
88
- * Exception occurs when resource is duplicated eg. unique constraint failed in db
89
- */
90
- class ResourceDuplicated extends Exception {
91
- }
92
- exports.ResourceDuplicated = ResourceDuplicated;
93
- /**
94
- * The exception that is thrown when JSON entity is checked against schema and is invalid
95
- */
96
- class JsonValidationFailed extends Exception {
97
- }
98
- exports.JsonValidationFailed = JsonValidationFailed;
99
- /**
100
- * The exception that is thrown if app not supports requestes `Accept` header eg. if client wants
101
- * html response but server can send only json.
102
- */
103
- class ExpectedResponseUnacceptable extends Exception {
104
- }
105
- exports.ExpectedResponseUnacceptable = ExpectedResponseUnacceptable;
106
- //# sourceMappingURL=index.js.map
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0,0 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- import { PathLike, ReadStream, WriteStream } from 'fs';
4
- import { DateTime } from 'luxon';
5
- export interface IStat {
6
- IsDirectory?: boolean;
7
- IsFile?: boolean;
8
- Size?: number;
9
- AccessTime?: DateTime;
10
- ModifiedTime?: DateTime;
11
- CreationTime?: DateTime;
12
- }
13
- export declare abstract class fs {
14
- abstract get Provider(): string;
15
- abstract download(path: PathLike): Promise<string>;
16
- abstract read(path: string, encoding: BufferEncoding): Promise<string>;
17
- abstract readStream(path: string): Promise<ReadStream>;
18
- abstract write(path: string, data: string | Buffer, encoding: BufferEncoding): Promise<void>;
19
- abstract writeStream(path: string): Promise<WriteStream>;
20
- abstract exists(path: PathLike): Promise<boolean>;
21
- abstract dirExists(path: PathLike): Promise<boolean>;
22
- abstract copy(path: string, dest: string): Promise<void>;
23
- abstract move(oldPath: PathLike, newPath: PathLike): Promise<void>;
24
- abstract rename(oldPath: PathLike, newPath: PathLike): Promise<void>;
25
- abstract unlink(path: PathLike): Promise<void>;
26
- abstract rm(path: PathLike): Promise<void>;
27
- abstract mkdir(path: PathLike): Promise<void>;
28
- abstract stat(path: PathLike): Promise<IStat>;
29
- abstract list(path: PathLike): Promise<string[]>;
30
- }
31
- /**
32
- * Abstract layer for file operations.
33
- * Basic implementation is just wrapper for native node fs functions
34
- *
35
- * It allows to wrap other libs eg. aws s3, ftp
36
- * and inject it into code without changing logic that use them.
37
- *
38
- * TODO: map errors to some kind of common errors shared with other implementations
39
- */
40
- export declare class fsNative extends fs {
41
- get Provider(): string;
42
- /**
43
- *
44
- * Tries to download file to local filesystem, then returns local filesystem path.
45
- * Native implementation simply returns local path and does nothing.
46
- *
47
- * @param path - file to download
48
- */
49
- download(path: PathLike): Promise<string>;
50
- /**
51
- * read all content of file
52
- */
53
- read(path: string, encoding: BufferEncoding): Promise<string>;
54
- readStream(path: string): Promise<ReadStream>;
55
- /**
56
- * Write to file string or buffer
57
- */
58
- write(path: string, data: string | Buffer, encoding: BufferEncoding): Promise<void>;
59
- writeStream(path: string): Promise<WriteStream>;
60
- /**
61
- * Checks if file existst
62
- * @param path - path to check
63
- */
64
- exists(path: PathLike): Promise<boolean>;
65
- dirExists(path: PathLike): Promise<boolean>;
66
- /**
67
- * Copy file to another location
68
- * @param path - src path
69
- * @param dest - dest path
70
- */
71
- copy(path: string, dest: string): Promise<void>;
72
- /**
73
- * Copy file to another location and deletes src file
74
- */
75
- move(oldPath: PathLike, newPath: PathLike): Promise<void>;
76
- /**
77
- * Change name of a file
78
- */
79
- rename(oldPath: PathLike, newPath: PathLike): Promise<void>;
80
- /**
81
- * Deletes file permanently
82
- *
83
- * @param path - path to file that will be deleted
84
- */
85
- unlink(path: PathLike): Promise<void>;
86
- /**
87
- *
88
- * Deletes dir recursively & all contents inside
89
- *
90
- * @param path - dir to remove
91
- */
92
- rm(path: PathLike): Promise<void>;
93
- /**
94
- *
95
- * Creates directory, recursively
96
- *
97
- * @param path - directory to create
98
- */
99
- mkdir(path: PathLike): Promise<void>;
100
- /**
101
- * Returns file statistics, not all fields may be accesible
102
- */
103
- stat(path: PathLike): Promise<IStat>;
104
- /**
105
- * List content of directory
106
- *
107
- * @param path - path to directory
108
- */
109
- list(path: PathLike): Promise<string[]>;
110
- }
@@ -1,170 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.fsNative = exports.fs = void 0;
10
- /* eslint-disable security/detect-non-literal-fs-filename */
11
- const index_1 = require("./../../exceptions/src/index");
12
- const fs_1 = require("fs");
13
- const promises_1 = require("node:fs/promises");
14
- const luxon_1 = require("luxon");
15
- const di_1 = require("@spinajs/di");
16
- class fs {
17
- }
18
- exports.fs = fs;
19
- /**
20
- * Abstract layer for file operations.
21
- * Basic implementation is just wrapper for native node fs functions
22
- *
23
- * It allows to wrap other libs eg. aws s3, ftp
24
- * and inject it into code without changing logic that use them.
25
- *
26
- * TODO: map errors to some kind of common errors shared with other implementations
27
- */
28
- let fsNative = class fsNative extends fs {
29
- get Provider() {
30
- return 'fs-local';
31
- }
32
- /**
33
- *
34
- * Tries to download file to local filesystem, then returns local filesystem path.
35
- * Native implementation simply returns local path and does nothing.
36
- *
37
- * @param path - file to download
38
- */
39
- async download(path) {
40
- const exists = await this.exists(path);
41
- if (!exists) {
42
- throw new index_1.IOFail(`file ${path} does not exists`);
43
- }
44
- return path;
45
- }
46
- /**
47
- * read all content of file
48
- */
49
- async read(path, encoding) {
50
- const fDesc = await (0, promises_1.open)(path, 'r');
51
- return fDesc.readFile({ encoding });
52
- }
53
- async readStream(path) {
54
- const fDesc = await (0, promises_1.open)(path, 'r');
55
- return fDesc.createReadStream();
56
- }
57
- /**
58
- * Write to file string or buffer
59
- */
60
- async write(path, data, encoding) {
61
- const fDesc = await (0, promises_1.open)(path, 'w');
62
- return await fDesc.writeFile(data, { encoding });
63
- }
64
- async writeStream(path) {
65
- const fDesc = await (0, promises_1.open)(path, 'w');
66
- return fDesc.createWriteStream();
67
- }
68
- /**
69
- * Checks if file existst
70
- * @param path - path to check
71
- */
72
- async exists(path) {
73
- try {
74
- await (0, promises_1.access)(path, fs_1.constants.F_OK);
75
- return true;
76
- }
77
- catch (_a) {
78
- return false;
79
- }
80
- }
81
- async dirExists(path) {
82
- // eslint-disable-next-line security/detect-non-literal-fs-filename
83
- return this.exists(path);
84
- }
85
- /**
86
- * Copy file to another location
87
- * @param path - src path
88
- * @param dest - dest path
89
- */
90
- async copy(path, dest) {
91
- await (0, promises_1.copyFile)(path, dest);
92
- }
93
- /**
94
- * Copy file to another location and deletes src file
95
- */
96
- async move(oldPath, newPath) {
97
- try {
98
- await (0, promises_1.rename)(oldPath, newPath);
99
- }
100
- catch (err) {
101
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
102
- if (err.code === 'EXDEV') {
103
- await (0, promises_1.copyFile)(oldPath, newPath);
104
- await (0, promises_1.unlink)(oldPath);
105
- }
106
- else {
107
- throw err;
108
- }
109
- }
110
- }
111
- /**
112
- * Change name of a file
113
- */
114
- async rename(oldPath, newPath) {
115
- await (0, promises_1.rename)(oldPath, newPath);
116
- }
117
- /**
118
- * Deletes file permanently
119
- *
120
- * @param path - path to file that will be deleted
121
- */
122
- async unlink(path) {
123
- await (0, promises_1.unlink)(path);
124
- }
125
- /**
126
- *
127
- * Deletes dir recursively & all contents inside
128
- *
129
- * @param path - dir to remove
130
- */
131
- async rm(path) {
132
- await (0, promises_1.rm)(path, { recursive: true, force: true, maxRetries: 3, retryDelay: 1000 });
133
- }
134
- /**
135
- *
136
- * Creates directory, recursively
137
- *
138
- * @param path - directory to create
139
- */
140
- async mkdir(path) {
141
- await (0, promises_1.mkdir)(path, { recursive: true });
142
- }
143
- /**
144
- * Returns file statistics, not all fields may be accesible
145
- */
146
- async stat(path) {
147
- const result = await (0, promises_1.stat)(path);
148
- return {
149
- IsDirectory: result.isDirectory(),
150
- IsFile: result.isFile(),
151
- CreationTime: luxon_1.DateTime.fromJSDate(result.ctime),
152
- ModifiedTime: luxon_1.DateTime.fromJSDate(result.mtime),
153
- AccessTime: luxon_1.DateTime.fromJSDate(result.atime),
154
- Size: result.size,
155
- };
156
- }
157
- /**
158
- * List content of directory
159
- *
160
- * @param path - path to directory
161
- */
162
- async list(path) {
163
- return await (0, promises_1.readdir)(path);
164
- }
165
- };
166
- fsNative = __decorate([
167
- (0, di_1.Injectable)('fs')
168
- ], fsNative);
169
- exports.fsNative = fsNative;
170
- //# sourceMappingURL=index.js.map
@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