@spinajs/fs-s3 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/config.d.ts +13 -0
- package/lib/cjs/config.d.ts.map +1 -0
- package/lib/cjs/config.js +26 -0
- package/lib/cjs/config.js.map +1 -0
- package/lib/cjs/index.d.ts +136 -110
- package/lib/cjs/index.d.ts.map +1 -1
- package/lib/cjs/index.js +381 -344
- package/lib/cjs/index.js.map +1 -1
- package/lib/mjs/config.d.ts +13 -0
- package/lib/mjs/config.d.ts.map +1 -0
- package/lib/mjs/config.js +24 -0
- package/lib/mjs/config.js.map +1 -0
- package/lib/mjs/index.d.ts +136 -110
- package/lib/mjs/index.d.ts.map +1 -1
- package/lib/mjs/index.js +352 -338
- package/lib/mjs/index.js.map +1 -1
- package/lib/tsconfig.cjs.tsbuildinfo +1 -1
- package/lib/tsconfig.mjs.tsbuildinfo +1 -1
- package/package.json +9 -8
|
@@ -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"}
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -1,111 +1,137 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
protected
|
|
24
|
-
protected
|
|
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
|
-
* @param
|
|
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
|
-
|
|
109
|
-
|
|
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
|
package/lib/cjs/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
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,eAAe,EAAE,MAAM,aAAa,CAAC;AACjF,OAAO,EACL,QAAQ,EACR,cAAc,EAMf,MAAM,oBAAoB,CA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