@spinajs/fs-s3 2.0.179 → 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.
@@ -0,0 +1,13 @@
1
+ declare const fs: {
2
+ fs: {
3
+ providers: {
4
+ service: string;
5
+ name: string;
6
+ basePath: string;
7
+ cleanupInterval: number;
8
+ maxFileAge: number;
9
+ }[];
10
+ };
11
+ };
12
+ export default fs;
13
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAMA,QAAA,MAAM,EAAE;;;;;;;;;;CAmBP,CAAC;AAEF,eAAe,EAAE,CAAC"}
@@ -0,0 +1,26 @@
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)(process.cwd(), path)));
6
+ }
7
+ const fs = {
8
+ fs: {
9
+ providers: [
10
+ /**
11
+ * provide temporary fs access for s3 files
12
+ */
13
+ {
14
+ service: 'fsNativeTemp',
15
+ name: 'fs-temp-s3',
16
+ basePath: dir('./../fs/temp-s3'),
17
+ // in ms
18
+ cleanupInterval: 3600 * 1000,
19
+ // in seconds
20
+ maxFileAge: 24 * 3600, // 1 day for temp files
21
+ },
22
+ ],
23
+ },
24
+ };
25
+ exports.default = fs;
26
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":";;AAAA,+BAAgD;AAEhD,SAAS,GAAG,CAAC,IAAY;IACvB,OAAO,IAAA,cAAO,EAAC,IAAA,gBAAS,EAAC,IAAA,WAAI,EAAC,OAAO,CAAC,GAAG,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;AACvD,CAAC;AAED,MAAM,EAAE,GAAG;IACT,EAAE,EAAE;QACF,SAAS,EAAE;YACT;;eAEG;YACH;gBACE,OAAO,EAAE,cAAc;gBACvB,IAAI,EAAE,YAAY;gBAClB,QAAQ,EAAE,GAAG,CAAC,iBAAiB,CAAC;gBAEhC,QAAQ;gBACR,eAAe,EAAE,IAAI,GAAG,IAAI;gBAE5B,aAAa;gBACb,UAAU,EAAE,EAAE,GAAG,IAAI,EAAE,uBAAuB;aAC/C;SACF;KACF;CACF,CAAC;AAEF,kBAAe,EAAE,CAAC"}
@@ -1,111 +1,137 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- import { Log } from '@spinajs/log-common';
4
- import { fs, IStat, IZipResult } from '@spinajs/fs';
5
- import { S3Client, S3ClientConfig } from '@aws-sdk/client-s3';
6
- import { ReadStream } from 'fs';
7
- export interface IS3Config {
8
- bucket: string;
9
- name: string;
10
- }
11
- /**
12
- * Abstract layer for file operations.
13
- * Basic implementation is just wrapper for native node fs functions
14
- *
15
- * It allows to wrap other libs eg. aws s3, ftp
16
- * and inject it into code without changing logic that use them.
17
- *
18
- * TODO: map errors to some kind of common errors shared with other implementations
19
- */
20
- export declare class fsS3 extends fs {
21
- Options: IS3Config;
22
- protected Logger: Log;
23
- protected S3: S3Client;
24
- protected AwsConfig: S3ClientConfig;
25
- /**
26
- * File system for temporary files
27
- */
28
- protected TempFs: fs;
29
- /**
30
- * Name of provider. We can have multiple providers of the same type but with different options.
31
- * Also used in InjectService decorator for mapping
32
- */
33
- get Name(): string;
34
- constructor(Options: IS3Config);
35
- resolve(): Promise<void>;
36
- /**
37
- *
38
- * Tries to download file to local filesystem, then returns local filesystem path.
39
- * Native implementation simply returns local path and does nothing.
40
- *
41
- * @param path - file to download
42
- */
43
- download(path: string): Promise<string>;
44
- /**
45
- * read all content of file
46
- */
47
- read(path: string, encoding: BufferEncoding): Promise<string | Buffer>;
48
- readStream(path: string, encoding?: BufferEncoding): Promise<ReadStream>;
49
- /**
50
- * Write to file string or buffer
51
- */
52
- write(path: string, data: string | Buffer, encoding?: BufferEncoding): Promise<void>;
53
- append(path: string, data: string | Buffer, encoding?: BufferEncoding): Promise<void>;
54
- upload(srcPath: string, destPath?: string): Promise<void>;
55
- writeStream(path: string, rStream?: ReadStream | BufferEncoding, encoding?: BufferEncoding): Promise<any>;
56
- /**
57
- * Checks if file existst
58
- * @param path - path to check
59
- */
60
- exists(path: string): Promise<boolean>;
61
- dirExists(): Promise<boolean>;
62
- /**
63
- * Copy file to another location
64
- * @param path - src path
65
- * @param dest - dest path
66
- */
67
- copy(path: string, dest: string): Promise<void>;
68
- /**
69
- * Copy file to another location and deletes src file
70
- */
71
- move(oldPath: string, newPath: string): Promise<void>;
72
- /**
73
- * Change name of a file
74
- */
75
- rename(oldPath: string, newPath: string): Promise<void>;
76
- /**
77
- * Deletes file permanently
78
- *
79
- * @param path - path to file that will be deleted
80
- * @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
81
- */
82
- unlink(path: string, onlyTemp?: boolean): Promise<void>;
83
- /**
84
- *
85
- * Deletes dir recursively & all contents inside
86
- *
87
- * @param path - dir to remove
88
- */
89
- rm(_path: string): Promise<void>;
90
- /**
91
- *
92
- * Creates directory, recursively
93
- *
94
- */
95
- mkdir(): Promise<void>;
96
- /**
97
- * Returns file statistics, not all fields may be accesible
98
- */
99
- stat(path: string): Promise<IStat>;
100
- tmppath(): string;
101
- /**
102
- * List content of directory
103
- *
104
- * @param path - path to directory
105
- */
106
- list(path: string): Promise<string[]>;
107
- unzip(_path: string, _destPath: string): Promise<void>;
108
- zip(path: string, zName?: string): Promise<IZipResult>;
109
- resolvePath(_path: string): string;
110
- }
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ /// <reference types="node" />
4
+ import { Log } from '@spinajs/log-common';
5
+ import { fs, IStat, IZipResult, FileInfoService } from '@spinajs/fs';
6
+ import { S3Client, S3ClientConfig } from '@aws-sdk/client-s3';
7
+ import { Readable } from 'stream';
8
+ export interface IS3Config {
9
+ bucket: string;
10
+ name: string;
11
+ }
12
+ /**
13
+ * Abstract layer for file operations.
14
+ * Basic implementation is just wrapper for native node fs functions
15
+ *
16
+ * It allows to wrap other libs eg. aws s3, ftp
17
+ * and inject it into code without changing logic that use them.
18
+ *
19
+ * TODO: map errors to some kind of common errors shared with other implementations
20
+ */
21
+ export declare class fsS3 extends fs {
22
+ Options: IS3Config;
23
+ protected Logger: Log;
24
+ protected S3: S3Client;
25
+ protected AwsConfig: S3ClientConfig;
26
+ /**
27
+ * File system for temporary files
28
+ */
29
+ protected TempFs: fs;
30
+ protected FileInfo: FileInfoService;
31
+ /**
32
+ * Name of provider. We can have multiple providers of the same type but with different options.
33
+ * Also used in InjectService decorator for mapping
34
+ */
35
+ get Name(): string;
36
+ constructor(Options: IS3Config);
37
+ resolve(): Promise<void>;
38
+ /**
39
+ *
40
+ * Tries to download file to local filesystem, then returns local filesystem path.
41
+ * Native implementation simply returns local path and does nothing.
42
+ *
43
+ * @param path - file to download
44
+ */
45
+ download(path: string): Promise<string>;
46
+ /**
47
+ * read all content of file
48
+ */
49
+ read(path: string, encoding: BufferEncoding): Promise<string | Buffer>;
50
+ /**
51
+ *
52
+ * @param path
53
+ * @param _encoding
54
+ * @returns
55
+ */
56
+ readStream(path: string, encoding?: BufferEncoding): Promise<Readable | NodeJS.ReadWriteStream>;
57
+ /**
58
+ * Write to file string or buffer
59
+ */
60
+ write(path: string, data: string | Buffer, encoding?: BufferEncoding): Promise<void>;
61
+ /**
62
+ * NOTE: append on s3 downloads file, appends to it, then uploads it again
63
+ * so it can be slow on large files
64
+ *
65
+ * @param path
66
+ * @param data
67
+ * @param encoding
68
+ */
69
+ append(path: string, data: string | Buffer, encoding?: BufferEncoding): Promise<void>;
70
+ upload(srcPath: string, destPath?: string): Promise<void>;
71
+ /**
72
+ *
73
+ * Gets metadata of file in s3 bucket
74
+ *
75
+ * @param path path to file
76
+ * @returns
77
+ */
78
+ getMetadata(path: string): Promise<Record<string, string>>;
79
+ /**
80
+ *
81
+ * Returns writable stream for given path
82
+ *
83
+ * @param path file path ( relative to base path of provider)
84
+ * @param rStream readable stream, must be provided beforehand
85
+ * @param encoding optional stream encoding
86
+ */
87
+ writeStream(_path: string, _encoding?: BufferEncoding): Promise<any>;
88
+ /**
89
+ * Checks if file existst
90
+ * @param path - path to check
91
+ */
92
+ exists(path: string): Promise<boolean>;
93
+ dirExists(): Promise<boolean>;
94
+ /**
95
+ * Copy file to another location
96
+ * @param path - src path
97
+ * @param dest - dest path
98
+ */
99
+ copy(path: string, dest: string, dstFs?: fs): Promise<void>;
100
+ /**
101
+ * Copy file to another location and deletes src file
102
+ */
103
+ move(oldPath: string, newPath: string, dstFs?: fs): Promise<void>;
104
+ /**
105
+ * Change name of a file
106
+ */
107
+ rename(oldPath: string, newPath: string): Promise<void>;
108
+ /**
109
+ *
110
+ * Deletes dir recursively & all contents inside
111
+ *
112
+ * @param path - dir to remove
113
+ */
114
+ rm(_path: string): Promise<void>;
115
+ /**
116
+ *
117
+ * Creates directory, recursively
118
+ *
119
+ */
120
+ mkdir(): Promise<void>;
121
+ isDir(_path: string): Promise<boolean>;
122
+ /**
123
+ * Returns file statistics, not all fields may be accesible
124
+ */
125
+ stat(path: string): Promise<IStat>;
126
+ tmppath(): string;
127
+ /**
128
+ * List content of directory
129
+ *
130
+ * @param path - path to directory
131
+ */
132
+ list(path: string): Promise<string[]>;
133
+ unzip(_path: string, _destPath: string): Promise<void>;
134
+ zip(_path: string, _dstFs?: fs, _dstFile?: string): Promise<IZipResult>;
135
+ resolvePath(_path: string): string;
136
+ }
111
137
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;AACA,OAAO,EAAE,GAAG,EAAU,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,UAAU,EAAc,MAAM,aAAa,CAAC;AAChE,OAAO,EAAE,QAAQ,EAAE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