@spinajs/fs 2.0.180 → 2.0.182
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
package/lib/mjs/interfaces.d.ts
CHANGED
|
@@ -1,158 +1,181 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
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
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
-
* @param path path
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
abstract
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
abstract
|
|
127
|
-
abstract
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
abstract
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
abstract
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
4
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
5
|
+
import { AsyncService, IInstanceCheck, IMappableService } from '@spinajs/di';
|
|
6
|
+
import { ReadStream, WriteStream } from 'fs';
|
|
7
|
+
import { DateTime } from 'luxon';
|
|
8
|
+
import { PassThrough } from 'stream';
|
|
9
|
+
export interface IProviderConfiguration {
|
|
10
|
+
name: string;
|
|
11
|
+
service: string;
|
|
12
|
+
}
|
|
13
|
+
export interface IFsConfiguration {
|
|
14
|
+
defaultProvider: string;
|
|
15
|
+
providers: IProviderConfiguration[];
|
|
16
|
+
}
|
|
17
|
+
export interface IStat {
|
|
18
|
+
IsDirectory?: boolean;
|
|
19
|
+
IsFile?: boolean;
|
|
20
|
+
Size?: number;
|
|
21
|
+
AccessTime?: DateTime;
|
|
22
|
+
ModifiedTime?: DateTime;
|
|
23
|
+
CreationTime?: DateTime;
|
|
24
|
+
AdditionalData?: unknown;
|
|
25
|
+
}
|
|
26
|
+
export interface IFileInfo {
|
|
27
|
+
/**
|
|
28
|
+
* Size in bytes
|
|
29
|
+
*/
|
|
30
|
+
FileSize: number;
|
|
31
|
+
Height?: number;
|
|
32
|
+
Width?: number;
|
|
33
|
+
Duration?: number;
|
|
34
|
+
FrameCount?: number;
|
|
35
|
+
FrameRate?: number;
|
|
36
|
+
Bitrate?: number;
|
|
37
|
+
Codec?: string;
|
|
38
|
+
LineCount?: number;
|
|
39
|
+
Encoding?: string;
|
|
40
|
+
MimeType?: string;
|
|
41
|
+
WordCount?: number;
|
|
42
|
+
AccessDate?: DateTime;
|
|
43
|
+
ModificationDate?: DateTime;
|
|
44
|
+
CreationDate?: DateTime;
|
|
45
|
+
/**
|
|
46
|
+
* Raw unprocessed data obtained from file info
|
|
47
|
+
*/
|
|
48
|
+
Raw?: {};
|
|
49
|
+
}
|
|
50
|
+
export interface IFsLocalOptions {
|
|
51
|
+
/**
|
|
52
|
+
* Full path to local directory where files are hold.
|
|
53
|
+
* All paths will be relative to this directory
|
|
54
|
+
*
|
|
55
|
+
* If path is not provided, it will behave like normal nodejs fs functions
|
|
56
|
+
*/
|
|
57
|
+
basePath?: string;
|
|
58
|
+
/**
|
|
59
|
+
* Instance name of this filesystem. Used to share fs instances.
|
|
60
|
+
*/
|
|
61
|
+
name: string;
|
|
62
|
+
}
|
|
63
|
+
export interface IFsLocalTempOptions extends IFsLocalOptions {
|
|
64
|
+
/**
|
|
65
|
+
* Should cleanup of old temp files be enabled
|
|
66
|
+
*/
|
|
67
|
+
cleanup: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Cleanup interval in seconds
|
|
70
|
+
* Default is 10 minutes
|
|
71
|
+
*/
|
|
72
|
+
cleanupInterval: number;
|
|
73
|
+
/**
|
|
74
|
+
* Max temp file age in seconds. Older thant this will be deleted.
|
|
75
|
+
* Default is 1 hour
|
|
76
|
+
*/
|
|
77
|
+
maxFileAge: number;
|
|
78
|
+
}
|
|
79
|
+
export interface IZipResult {
|
|
80
|
+
/**
|
|
81
|
+
* Destination filesystem ( default is fs-temp for zipped files)
|
|
82
|
+
*/
|
|
83
|
+
fs: fs;
|
|
84
|
+
asFilePath(): string;
|
|
85
|
+
asStream(): ReadStream;
|
|
86
|
+
asBase64(): string;
|
|
87
|
+
unlink(): void;
|
|
88
|
+
}
|
|
89
|
+
export declare abstract class fs extends AsyncService implements IMappableService, IInstanceCheck {
|
|
90
|
+
get ServiceName(): string;
|
|
91
|
+
__checkInstance__(creationOptions: any): boolean;
|
|
92
|
+
abstract Name: string;
|
|
93
|
+
/**
|
|
94
|
+
* Downloads file to local storage and returns path to it.
|
|
95
|
+
* If used on local storage provider eg. hard drive it only returns full path to file
|
|
96
|
+
*
|
|
97
|
+
* On remote storage provivers eg. amazon s3 - it tries to download it to local disk first and returns
|
|
98
|
+
* full path.
|
|
99
|
+
*
|
|
100
|
+
* Returns local path to file
|
|
101
|
+
*
|
|
102
|
+
* @param path path to download
|
|
103
|
+
*/
|
|
104
|
+
abstract download(path: string): Promise<string>;
|
|
105
|
+
/**
|
|
106
|
+
* Copies local file into fs
|
|
107
|
+
*
|
|
108
|
+
* @param srcPath source path ( full absolute path eg. file from local disk )
|
|
109
|
+
* @param destPath dest path ( relative to base path of provider )
|
|
110
|
+
*/
|
|
111
|
+
abstract upload(srcPath: string, destPath?: string): Promise<void>;
|
|
112
|
+
/**
|
|
113
|
+
*
|
|
114
|
+
* Returns hash of file
|
|
115
|
+
*
|
|
116
|
+
* @param srcPath file to calculate hash
|
|
117
|
+
* @param algo optional hash alghoritm, default is md5
|
|
118
|
+
*/
|
|
119
|
+
hash(path: string, algo?: string): Promise<string>;
|
|
120
|
+
/**
|
|
121
|
+
*
|
|
122
|
+
* Returns full LOCAL path to file
|
|
123
|
+
*
|
|
124
|
+
* @param path path to resolve
|
|
125
|
+
*/
|
|
126
|
+
abstract resolvePath(path: string): string;
|
|
127
|
+
abstract read(path: string, encoding?: BufferEncoding): Promise<string | Buffer>;
|
|
128
|
+
abstract readStream(path: string, encoding?: BufferEncoding): Promise<NodeJS.ReadableStream>;
|
|
129
|
+
abstract write(path: string, data: string | Buffer, encoding?: BufferEncoding): Promise<void>;
|
|
130
|
+
abstract writeStream(path: string, encoding?: BufferEncoding): Promise<WriteStream | PassThrough>;
|
|
131
|
+
abstract writeStream(path: string, readStream: NodeJS.ReadableStream | BufferEncoding, encoding?: BufferEncoding): Promise<WriteStream | PassThrough>;
|
|
132
|
+
abstract exists(path: string): Promise<boolean>;
|
|
133
|
+
abstract dirExists(path: string): Promise<boolean>;
|
|
134
|
+
abstract copy(path: string, dest: string, dstFs?: fs): Promise<void>;
|
|
135
|
+
abstract move(oldPath: string, newPath: string, dstFs?: fs): Promise<void>;
|
|
136
|
+
abstract rename(oldPath: string, newPath: string): Promise<void>;
|
|
137
|
+
abstract rm(path: string): Promise<void>;
|
|
138
|
+
abstract mkdir(path: string): Promise<void>;
|
|
139
|
+
abstract stat(path: string): Promise<IStat>;
|
|
140
|
+
abstract list(path: string): Promise<string[]>;
|
|
141
|
+
abstract tmppath(): string;
|
|
142
|
+
abstract append(path: string, data: string | Buffer, encoding?: BufferEncoding): Promise<void>;
|
|
143
|
+
/**
|
|
144
|
+
*
|
|
145
|
+
* Compress specified file or dir in provided path. If
|
|
146
|
+
* Dir is compressed recursively
|
|
147
|
+
*
|
|
148
|
+
* @param path - path to zip
|
|
149
|
+
* @param dstFile - destination file name
|
|
150
|
+
*/
|
|
151
|
+
abstract zip(path: string | string[], dstFs?: fs, dstFile?: string): Promise<IZipResult>;
|
|
152
|
+
/**
|
|
153
|
+
* Decompress given file to destination path
|
|
154
|
+
*
|
|
155
|
+
* @param path path to zip file
|
|
156
|
+
* @param destPath path to destination dir
|
|
157
|
+
*/
|
|
158
|
+
abstract unzip(srcPath: string, destPath: string, dstFs?: fs): Promise<void>;
|
|
159
|
+
/**
|
|
160
|
+
*
|
|
161
|
+
* Checks if given path is dir
|
|
162
|
+
*
|
|
163
|
+
* @param path path to check
|
|
164
|
+
*/
|
|
165
|
+
abstract isDir(path: string): Promise<boolean>;
|
|
166
|
+
tmpname(): string;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* File information service, obtain file props, metadata etc.
|
|
170
|
+
* Eg. movie resolution, image, codec etc. if possible
|
|
171
|
+
*/
|
|
172
|
+
export declare abstract class FileInfoService {
|
|
173
|
+
abstract getInfo(pathToFile: string): Promise<IFileInfo>;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* File hasher, to create unique hash for file
|
|
177
|
+
*/
|
|
178
|
+
export declare abstract class FileHasher {
|
|
179
|
+
abstract hash(pathToFile: string): Promise<string>;
|
|
180
|
+
}
|
|
158
181
|
//# sourceMappingURL=interfaces.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../src/interfaces.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../src/interfaces.ts"],"names":[],"mappings":";;;;AACA,OAAO,EAAE,YAAY,EAAM,cAAc,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACjF,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,IAAI,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAGrC,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AACD,MAAM,WAAW,gBAAgB;IAC/B,eAAe,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,sBAAsB,EAAE,CAAC;CACrC;AAED,MAAM,WAAW,KAAK;IACpB,WAAW,CAAC,EAAE,OAAO,C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AAE,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAEnF;;;;;OAKG;aACa,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAE9C,OAAO;CAGf;AAED;;;GAGG;AACH,8BAAsB,eAAe;aACnB,OAAO,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;CAChE;AAED;;GAEG;AACH,8BAAsB,UAAU;aACd,IAAI,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAC1D"}
|
package/lib/mjs/interfaces.js
CHANGED
|
@@ -1,28 +1,39 @@
|
|
|
1
|
-
/* eslint-disable security/detect-non-literal-fs-filename */
|
|
2
|
-
import { AsyncService } from '@spinajs/di';
|
|
3
|
-
import { v4 as uuidv4 } from 'uuid';
|
|
4
|
-
export class fs extends AsyncService {
|
|
5
|
-
get ServiceName() {
|
|
6
|
-
return this.Name;
|
|
7
|
-
}
|
|
8
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
|
-
__checkInstance__(creationOptions) {
|
|
10
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
11
|
-
return this.Name === creationOptions[0].name;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
1
|
+
/* eslint-disable security/detect-non-literal-fs-filename */
|
|
2
|
+
import { AsyncService, DI } from '@spinajs/di';
|
|
3
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
4
|
+
export class fs extends AsyncService {
|
|
5
|
+
get ServiceName() {
|
|
6
|
+
return this.Name;
|
|
7
|
+
}
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
|
+
__checkInstance__(creationOptions) {
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
11
|
+
return this.Name === creationOptions[0].name;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
*
|
|
15
|
+
* Returns hash of file
|
|
16
|
+
*
|
|
17
|
+
* @param srcPath file to calculate hash
|
|
18
|
+
* @param algo optional hash alghoritm, default is md5
|
|
19
|
+
*/
|
|
20
|
+
async hash(path, algo) {
|
|
21
|
+
const hasher = DI.resolve(FileHasher, [algo]);
|
|
22
|
+
return hasher.hash(this.resolvePath(path));
|
|
23
|
+
}
|
|
24
|
+
tmpname() {
|
|
25
|
+
return uuidv4();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* File information service, obtain file props, metadata etc.
|
|
30
|
+
* Eg. movie resolution, image, codec etc. if possible
|
|
31
|
+
*/
|
|
32
|
+
export class FileInfoService {
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* File hasher, to create unique hash for file
|
|
36
|
+
*/
|
|
37
|
+
export class FileHasher {
|
|
38
|
+
}
|
|
28
39
|
//# sourceMappingURL=interfaces.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../src/interfaces.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,OAAO,EAAE,YAAY,EAAoC,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../src/interfaces.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,OAAO,EAAE,YAAY,EAAE,EAAE,EAAoC,MAAM,aAAa,CAAC;AAIjF,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AAyGpC,MAAM,OAAgB,EAAG,SAAQ,YAAY;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;IAyBC;;;;;;KAMC;IACI,KAAK,CAAC,IAAI,CAAC,IAAY,EAAE,IAAa;QAC3C,MAAM,MAAM,GAAG,EAAE,CAAC,OAAO,CAAa,UAAU,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;QAC1D,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC;IAC7C,CAAC;IAuDM,OAAO;QACZ,OAAO,MAAM,EAAE,CAAC;IAClB,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAgB,eAAe;CAEpC;AAED;;GAEG;AACH,MAAM,OAAgB,UAAU;CAE/B"}
|
|
@@ -1,101 +1,97 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
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
|
-
* @param
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
*
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
*
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
unzip(path: string, destPath: string): Promise<void>;
|
|
98
|
-
zip(path: string, zName?: string): Promise<IZipResult>;
|
|
99
|
-
resolvePath(path: string): string;
|
|
100
|
-
}
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
4
|
+
import { ReadStream } from 'fs';
|
|
5
|
+
import { fs, IFsLocalOptions, IStat, IZipResult } from './interfaces.js';
|
|
6
|
+
import { Log } from '@spinajs/log-common';
|
|
7
|
+
/**
|
|
8
|
+
* Abstract layer for file operations.
|
|
9
|
+
* Basic implementation is just wrapper for native node fs functions
|
|
10
|
+
*
|
|
11
|
+
* It allows to wrap other libs eg. aws s3, ftp
|
|
12
|
+
* and inject it into code without changing logic that use them.
|
|
13
|
+
*
|
|
14
|
+
* TODO: map errors to some kind of common errors shared with other implementations
|
|
15
|
+
*/
|
|
16
|
+
export declare class fsNative<T extends IFsLocalOptions> extends fs {
|
|
17
|
+
Options: T;
|
|
18
|
+
protected Logger: Log;
|
|
19
|
+
/**
|
|
20
|
+
* Name of provider. We can have multiple providers of the same type but with different options.
|
|
21
|
+
* Also used in InjectService decorator for mapping
|
|
22
|
+
*/
|
|
23
|
+
get Name(): string;
|
|
24
|
+
constructor(Options: T);
|
|
25
|
+
resolve(): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
*
|
|
28
|
+
* Tries to download file to local filesystem, then returns local filesystem path.
|
|
29
|
+
* Native implementation simply returns local path and does nothing.
|
|
30
|
+
*
|
|
31
|
+
* @param path - file to download
|
|
32
|
+
*/
|
|
33
|
+
download(path: string): Promise<string>;
|
|
34
|
+
upload(srcPath: string, destPath?: string): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* read all content of file
|
|
37
|
+
*/
|
|
38
|
+
read(path: string, encoding?: BufferEncoding): Promise<string | Buffer>;
|
|
39
|
+
readStream(path: string, encoding?: BufferEncoding): Promise<ReadStream>;
|
|
40
|
+
/**
|
|
41
|
+
* Write to file string or buffer
|
|
42
|
+
*/
|
|
43
|
+
write(path: string, data: string | Buffer, encoding: BufferEncoding): Promise<void>;
|
|
44
|
+
append(path: string, data: string | Buffer, encoding?: BufferEncoding): Promise<void>;
|
|
45
|
+
writeStream(path: string, rStream?: BufferEncoding | NodeJS.ReadStream, encoding?: BufferEncoding): Promise<import("fs").WriteStream>;
|
|
46
|
+
/**
|
|
47
|
+
* Checks if file existst
|
|
48
|
+
* @param path - path to check
|
|
49
|
+
*/
|
|
50
|
+
exists(path: string): Promise<boolean>;
|
|
51
|
+
dirExists(path: string): Promise<boolean>;
|
|
52
|
+
/**
|
|
53
|
+
* Copy file or dir to another location
|
|
54
|
+
* @param path - src path
|
|
55
|
+
* @param dest - dest path
|
|
56
|
+
*/
|
|
57
|
+
copy(path: string, dest: string, dstFs?: fs): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Copy file to another location and deletes src file
|
|
60
|
+
*/
|
|
61
|
+
move(oldPath: string, newPath: string, dstFs?: fs): Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* Change name of a file
|
|
64
|
+
*/
|
|
65
|
+
rename(oldPath: string, newPath: string): Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
*
|
|
68
|
+
* Deletes file OR
|
|
69
|
+
* Deletes dir recursively & all contents inside
|
|
70
|
+
*
|
|
71
|
+
* @param path - dir to remove
|
|
72
|
+
*/
|
|
73
|
+
rm(path: string): Promise<void>;
|
|
74
|
+
/**
|
|
75
|
+
*
|
|
76
|
+
* Creates directory, recursively
|
|
77
|
+
*
|
|
78
|
+
* @param path - directory to create
|
|
79
|
+
*/
|
|
80
|
+
mkdir(path: string): Promise<void>;
|
|
81
|
+
/**
|
|
82
|
+
* Returns file statistics, not all fields may be accesible
|
|
83
|
+
*/
|
|
84
|
+
stat(path: string): Promise<IStat>;
|
|
85
|
+
tmppath(): string;
|
|
86
|
+
/**
|
|
87
|
+
* List content of directory
|
|
88
|
+
*
|
|
89
|
+
* @param path - path to directory
|
|
90
|
+
*/
|
|
91
|
+
list(path: string): Promise<string[]>;
|
|
92
|
+
unzip(path: string, destPath?: string, dstFs?: fs): Promise<void>;
|
|
93
|
+
isDir(path: string): Promise<boolean>;
|
|
94
|
+
zip(path: string | string[], dstFs?: fs, dstFile?: string): Promise<IZipResult>;
|
|
95
|
+
resolvePath(path: string): string;
|
|
96
|
+
}
|
|
101
97
|
//# sourceMappingURL=local-provider.d.ts.map
|