@did-space/fs-driver 0.2.5

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/README.md ADDED
@@ -0,0 +1 @@
1
+ # DID Spaces Core
@@ -0,0 +1,29 @@
1
+ import { SpaceConfigProtocol, SpaceConfig, PermissionOptions } from '@did-space/core';
2
+ export declare class FsSpaceConfig implements SpaceConfigProtocol {
3
+ private key;
4
+ constructor({ root }: {
5
+ root: string;
6
+ });
7
+ createConfig(spaceConfig: SpaceConfig): Promise<void>;
8
+ destroyConfig(): Promise<void>;
9
+ set<T = any>(key: keyof SpaceConfig, value: T): Promise<void>;
10
+ get<T = any>(key: keyof SpaceConfig, defaultValue?: T): Promise<T>;
11
+ private getPermission;
12
+ /**
13
+ *
14
+ * @see https://blog.csdn.net/a1173537204/article/details/89765932
15
+ * @private
16
+ * @param {PermissionOptions} { fromAppDid, toAppDid }
17
+ * @param {number} permission
18
+ * @param {boolean} status
19
+ * @return {*} {Promise<void>}
20
+ * @memberof FsSpaceConfig
21
+ */
22
+ private setPermission;
23
+ setListable(options: PermissionOptions, status: boolean): Promise<void>;
24
+ setReadable(options: PermissionOptions, status: boolean): Promise<void>;
25
+ setWritable(options: PermissionOptions, status: boolean): Promise<void>;
26
+ isListable(options: PermissionOptions): Promise<boolean>;
27
+ isReadable(options: PermissionOptions): Promise<boolean>;
28
+ isWritable(options: PermissionOptions): Promise<boolean>;
29
+ }
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
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.FsSpaceConfig = void 0;
16
+ const path_1 = require("path");
17
+ const js_yaml_1 = __importDefault(require("js-yaml"));
18
+ const fs_extra_1 = __importDefault(require("fs-extra"));
19
+ const core_1 = require("@did-space/core");
20
+ class FsSpaceConfig {
21
+ constructor({ root }) {
22
+ this.key = (0, path_1.join)(root, 'config.yml');
23
+ }
24
+ createConfig(spaceConfig) {
25
+ return __awaiter(this, void 0, void 0, function* () {
26
+ if (fs_extra_1.default.existsSync(this.key)) {
27
+ throw new Error('The configuration has been initialized and cannot be modified');
28
+ }
29
+ const { error } = core_1.SpaceConfigSchema.validate(spaceConfig);
30
+ if (error) {
31
+ core_1.logger.error(error);
32
+ throw error;
33
+ }
34
+ // 保存配置在space下的config.yml
35
+ yield fs_extra_1.default.outputFile(this.key, js_yaml_1.default.dump(spaceConfig));
36
+ });
37
+ }
38
+ destroyConfig() {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ return fs_extra_1.default.remove(this.key);
41
+ });
42
+ }
43
+ // FIXME: @yejianchao 待实现,可以把key对应的Value的类型也带出来?我想到了一种方法,但是我觉得太粗糙了
44
+ set(key, value) {
45
+ return __awaiter(this, void 0, void 0, function* () {
46
+ const data = js_yaml_1.default.load((yield fs_extra_1.default.readFile(this.key)).toString());
47
+ data[key] = value;
48
+ yield fs_extra_1.default.outputFile(this.key, js_yaml_1.default.dump(data));
49
+ });
50
+ }
51
+ get(key, defaultValue = undefined) {
52
+ var _a;
53
+ return __awaiter(this, void 0, void 0, function* () {
54
+ const data = js_yaml_1.default.load((yield fs_extra_1.default.readFile(this.key)).toString());
55
+ return (_a = data[key]) !== null && _a !== void 0 ? _a : defaultValue;
56
+ });
57
+ }
58
+ getPermission({ fromAppDid, toAppDid }) {
59
+ var _a;
60
+ return __awaiter(this, void 0, void 0, function* () {
61
+ const permissions = yield this.get('permissions');
62
+ return ((_a = permissions === null || permissions === void 0 ? void 0 : permissions[fromAppDid]) === null || _a === void 0 ? void 0 : _a[toAppDid]) || 0;
63
+ });
64
+ }
65
+ /**
66
+ *
67
+ * @see https://blog.csdn.net/a1173537204/article/details/89765932
68
+ * @private
69
+ * @param {PermissionOptions} { fromAppDid, toAppDid }
70
+ * @param {number} permission
71
+ * @param {boolean} status
72
+ * @return {*} {Promise<void>}
73
+ * @memberof FsSpaceConfig
74
+ */
75
+ setPermission({ fromAppDid, toAppDid }, permission, status) {
76
+ var _a, _b;
77
+ return __awaiter(this, void 0, void 0, function* () {
78
+ const permissions = yield this.get('permissions', {});
79
+ // 我想知道原来的权限是啥样的?
80
+ const oldPermission = ((_a = permissions === null || permissions === void 0 ? void 0 : permissions[fromAppDid]) === null || _a === void 0 ? void 0 : _a[toAppDid]) || 0;
81
+ permissions[fromAppDid] = Object.assign((_b = permissions === null || permissions === void 0 ? void 0 : permissions[fromAppDid]) !== null && _b !== void 0 ? _b : {}, Object.assign(Object.assign({}, permissions === null || permissions === void 0 ? void 0 : permissions[fromAppDid]), {
82
+ // eslint-disable-next-line no-bitwise
83
+ [toAppDid]: status ? oldPermission | permission : oldPermission & ~permission }));
84
+ yield this.set('permissions', permissions);
85
+ });
86
+ }
87
+ setListable(options, status) {
88
+ return __awaiter(this, void 0, void 0, function* () {
89
+ return this.setPermission(options, core_1.Scopes['list:object'], status);
90
+ });
91
+ }
92
+ setReadable(options, status) {
93
+ return __awaiter(this, void 0, void 0, function* () {
94
+ return this.setPermission(options, core_1.Scopes['read:object'], status);
95
+ });
96
+ }
97
+ setWritable(options, status) {
98
+ return __awaiter(this, void 0, void 0, function* () {
99
+ return this.setPermission(options, core_1.Scopes['write:object'], status);
100
+ });
101
+ }
102
+ isListable(options) {
103
+ return __awaiter(this, void 0, void 0, function* () {
104
+ const permission = yield this.getPermission(options);
105
+ // eslint-disable-next-line no-bitwise
106
+ return Boolean((permission & core_1.Scopes['list:object']) === core_1.Scopes['list:object']);
107
+ });
108
+ }
109
+ isReadable(options) {
110
+ return __awaiter(this, void 0, void 0, function* () {
111
+ const permission = yield this.getPermission(options);
112
+ // eslint-disable-next-line no-bitwise
113
+ return Boolean((permission & core_1.Scopes['read:object']) === core_1.Scopes['read:object']);
114
+ });
115
+ }
116
+ isWritable(options) {
117
+ return __awaiter(this, void 0, void 0, function* () {
118
+ const permission = yield this.getPermission(options);
119
+ // eslint-disable-next-line no-bitwise
120
+ return Boolean((permission & core_1.Scopes['write:object']) === core_1.Scopes['write:object']);
121
+ });
122
+ }
123
+ }
124
+ exports.FsSpaceConfig = FsSpaceConfig;
@@ -0,0 +1,8 @@
1
+ import { BaseDriver, DriverOptions, SpaceConfigProtocol, SpaceOperatorProtocol } from '@did-space/core';
2
+ export declare class FsDriver extends BaseDriver {
3
+ private _spaceConfig;
4
+ private _spaceOperator;
5
+ constructor(options: DriverOptions);
6
+ get spaceOperator(): SpaceOperatorProtocol;
7
+ get spaceConfig(): SpaceConfigProtocol;
8
+ }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FsDriver = void 0;
4
+ const core_1 = require("@did-space/core");
5
+ const config_1 = require("../config");
6
+ const operator_1 = require("../operator");
7
+ class FsDriver extends core_1.BaseDriver {
8
+ constructor(options) {
9
+ super(options);
10
+ this._spaceConfig = new config_1.FsSpaceConfig(options);
11
+ this._spaceOperator = new operator_1.FsSpaceOperator(options);
12
+ }
13
+ get spaceOperator() {
14
+ return this._spaceOperator;
15
+ }
16
+ get spaceConfig() {
17
+ return this._spaceConfig;
18
+ }
19
+ }
20
+ exports.FsDriver = FsDriver;
@@ -0,0 +1,3 @@
1
+ export * from './config';
2
+ export * from './fs';
3
+ export * from './operator';
package/dist/index.js ADDED
@@ -0,0 +1,19 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./config"), exports);
18
+ __exportStar(require("./fs"), exports);
19
+ __exportStar(require("./operator"), exports);
@@ -0,0 +1,45 @@
1
+ /// <reference types="node" />
2
+ import { ReadOptions, WriteOptions, SpaceOperatorProtocol, SpaceConfig, AppSpaceOptions, DeleteOptions, ListOptions, Object, Data, ListsOptions, GetHashOptions } from '@did-space/core';
3
+ import { Stream } from 'stream';
4
+ type PathStatus = {
5
+ objects: number;
6
+ lastModified: number;
7
+ size: number;
8
+ };
9
+ export declare class FsSpaceOperator implements SpaceOperatorProtocol {
10
+ readonly options: {
11
+ root: string;
12
+ };
13
+ static readonly APPS = "apps";
14
+ constructor(options: {
15
+ root: string;
16
+ });
17
+ createSpace(_spaceConfig: SpaceConfig): Promise<void>;
18
+ destroySpace(): Promise<void>;
19
+ isSpaceCreated(): Promise<boolean>;
20
+ getSpaceSize(): Promise<number>;
21
+ getPathStatus(path: string): Promise<PathStatus>;
22
+ createAppSpace(options: AppSpaceOptions): Promise<void>;
23
+ destroyAppSpace(options: AppSpaceOptions): Promise<void>;
24
+ getAppSpacePath(options: AppSpaceOptions): Promise<string>;
25
+ private getObjectKey;
26
+ write(options: WriteOptions): Promise<void>;
27
+ delete(options: DeleteOptions): Promise<void>;
28
+ read(options: ReadOptions): Promise<Stream>;
29
+ getHash(options: GetHashOptions): Promise<string>;
30
+ exists(options: ReadOptions): Promise<boolean>;
31
+ /**
32
+ *
33
+ *
34
+ * @param {ListsOptions} options
35
+ * @return {*} {Promise<Object[]>}
36
+ * @memberof FsSpaceOperator
37
+ */
38
+ lists(options: ListsOptions): Promise<Object[]>;
39
+ list(options: ListOptions): Promise<Object>;
40
+ writeAsOwner(key: string, data: Data): Promise<void>;
41
+ deleteAsOwner(key: string): Promise<void>;
42
+ readAsOwner(key: string): Promise<Stream>;
43
+ existsAsOwner(key: string): Promise<boolean>;
44
+ }
45
+ export {};
@@ -0,0 +1,253 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
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.FsSpaceOperator = void 0;
16
+ /* eslint-disable @typescript-eslint/no-unused-vars */
17
+ const core_1 = require("@did-space/core");
18
+ const filehound_1 = __importDefault(require("filehound"));
19
+ const fs_extra_1 = __importDefault(require("fs-extra"));
20
+ const lodash_1 = require("lodash");
21
+ const mime_types_1 = __importDefault(require("mime-types"));
22
+ const path_1 = require("path");
23
+ const stream_1 = require("stream");
24
+ const hasha_1 = __importDefault(require("hasha"));
25
+ const read_stream_to_file_1 = require("./read-stream-to-file");
26
+ class FsSpaceOperator {
27
+ constructor(options) {
28
+ this.options = options;
29
+ }
30
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
31
+ createSpace(_spaceConfig) {
32
+ return __awaiter(this, void 0, void 0, function* () {
33
+ return fs_extra_1.default.ensureDir(this.options.root);
34
+ });
35
+ }
36
+ destroySpace() {
37
+ return __awaiter(this, void 0, void 0, function* () {
38
+ return fs_extra_1.default.remove(this.options.root);
39
+ });
40
+ }
41
+ isSpaceCreated() {
42
+ return __awaiter(this, void 0, void 0, function* () {
43
+ return fs_extra_1.default.existsSync(this.options.root);
44
+ });
45
+ }
46
+ getSpaceSize() {
47
+ return __awaiter(this, void 0, void 0, function* () {
48
+ const pathStatus = yield this.getPathStatus(this.options.root);
49
+ return pathStatus.size;
50
+ });
51
+ }
52
+ getPathStatus(path) {
53
+ return __awaiter(this, void 0, void 0, function* () {
54
+ const files = filehound_1.default.create()
55
+ .paths(path)
56
+ .includeFileStats()
57
+ .findSync();
58
+ const pathStatus = files.reduce((_pathStatus, file) => {
59
+ _pathStatus.size += file.stats.size;
60
+ _pathStatus.objects++;
61
+ _pathStatus.lastModified = Math.max(new Date(file.stats.mtime).getTime(), _pathStatus.lastModified);
62
+ return _pathStatus;
63
+ }, {
64
+ size: 0,
65
+ objects: 0,
66
+ lastModified: 0,
67
+ });
68
+ return pathStatus;
69
+ });
70
+ }
71
+ createAppSpace(options) {
72
+ return __awaiter(this, void 0, void 0, function* () {
73
+ return fs_extra_1.default.ensureDir(yield this.getAppSpacePath(options));
74
+ });
75
+ }
76
+ destroyAppSpace(options) {
77
+ return __awaiter(this, void 0, void 0, function* () {
78
+ return fs_extra_1.default.remove(yield this.getAppSpacePath(options));
79
+ });
80
+ }
81
+ getAppSpacePath(options) {
82
+ return __awaiter(this, void 0, void 0, function* () {
83
+ return (0, path_1.join)(this.options.root, FsSpaceOperator.APPS, options.appDid);
84
+ });
85
+ }
86
+ getObjectKey(options) {
87
+ return __awaiter(this, void 0, void 0, function* () {
88
+ return (0, path_1.join)(yield this.getAppSpacePath(options), options.key);
89
+ });
90
+ }
91
+ write(options) {
92
+ return __awaiter(this, void 0, void 0, function* () {
93
+ const objectPath = yield this.getObjectKey(options);
94
+ const { data } = options;
95
+ if (objectPath.endsWith('/')) {
96
+ // 这是一个文件夹
97
+ yield fs_extra_1.default.ensureDir(objectPath);
98
+ }
99
+ else if ((0, lodash_1.isString)(data) || (0, lodash_1.isBuffer)(data)) {
100
+ yield fs_extra_1.default.outputFile(objectPath, data);
101
+ }
102
+ else if (data instanceof stream_1.Stream || data instanceof stream_1.Readable || (0, lodash_1.isFunction)(data === null || data === void 0 ? void 0 : data.pipe)) {
103
+ fs_extra_1.default.ensureDirSync((0, path_1.dirname)(objectPath));
104
+ yield (0, read_stream_to_file_1.readStreamToFile)(data, fs_extra_1.default.createWriteStream(objectPath));
105
+ }
106
+ else {
107
+ throw new Error('Data is unsupported format, expected data to be one of: string | Buffer | ReadableStream.');
108
+ }
109
+ });
110
+ }
111
+ delete(options) {
112
+ return __awaiter(this, void 0, void 0, function* () {
113
+ return fs_extra_1.default.remove(yield this.getObjectKey(options));
114
+ });
115
+ }
116
+ read(options) {
117
+ return __awaiter(this, void 0, void 0, function* () {
118
+ const objectKey = yield this.getObjectKey(options);
119
+ return fs_extra_1.default.createReadStream(objectKey);
120
+ });
121
+ }
122
+ getHash(options) {
123
+ return __awaiter(this, void 0, void 0, function* () {
124
+ const streamData = yield this.read(options);
125
+ const hash = yield hasha_1.default.fromStream(streamData, {
126
+ algorithm: 'md5',
127
+ });
128
+ return hash;
129
+ });
130
+ }
131
+ exists(options) {
132
+ return __awaiter(this, void 0, void 0, function* () {
133
+ return fs_extra_1.default.existsSync(yield this.getObjectKey(options));
134
+ });
135
+ }
136
+ /**
137
+ *
138
+ *
139
+ * @param {ListsOptions} options
140
+ * @return {*} {Promise<Object[]>}
141
+ * @memberof FsSpaceOperator
142
+ */
143
+ lists(options) {
144
+ return __awaiter(this, void 0, void 0, function* () {
145
+ const path = (0, path_1.join)(this.options.root, options.key);
146
+ // 以 非递归的方式 && 显示文件夹 的方式列出当前文件
147
+ if (!options.recursive) {
148
+ const objectNames = fs_extra_1.default.readdirSync(path);
149
+ return Promise.all(objectNames.map((objectName) => __awaiter(this, void 0, void 0, function* () {
150
+ const objectKey = (0, path_1.join)(this.options.root, options.key, objectName);
151
+ const fileStat = fs_extra_1.default.statSync(objectKey);
152
+ const isDir = fileStat.isDirectory();
153
+ const directorySuffixes = isDir ? '/' : '';
154
+ const key = (0, path_1.join)(options.key, objectName, directorySuffixes);
155
+ const name = (0, path_1.join)(objectName, directorySuffixes);
156
+ let { size } = fileStat;
157
+ let lastModified = new Date(fileStat.mtime).getTime();
158
+ if (isDir) {
159
+ const pathStatus = yield this.getPathStatus(objectKey);
160
+ size = pathStatus.size;
161
+ lastModified = pathStatus.lastModified;
162
+ }
163
+ return {
164
+ key,
165
+ name,
166
+ isDir,
167
+ size,
168
+ lastModified,
169
+ editable: core_1.Space.editable(key),
170
+ mimeType: mime_types_1.default.lookup(objectName) || 'unknown',
171
+ };
172
+ })));
173
+ }
174
+ if (options.recursive && options.ignoreDirectories) {
175
+ const files = filehound_1.default.create()
176
+ .paths(path)
177
+ .includeFileStats()
178
+ .findSync();
179
+ return files.map((file) => {
180
+ const key = file.path.replace(path, '');
181
+ return {
182
+ key,
183
+ name: (0, path_1.basename)(key),
184
+ isDir: key.endsWith('/'),
185
+ size: file.stats.size,
186
+ lastModified: new Date(file.stats.mtime).getTime(),
187
+ editable: true,
188
+ mimeType: mime_types_1.default.lookup((0, path_1.basename)(key)) || 'unknown',
189
+ };
190
+ });
191
+ }
192
+ throw new Error(`Filter methods not yet supported:\n ${JSON.stringify(options, null, 2)}`);
193
+ });
194
+ }
195
+ list(options) {
196
+ return __awaiter(this, void 0, void 0, function* () {
197
+ const objectKey = (0, path_1.join)(this.options.root, options.key);
198
+ if (!fs_extra_1.default.existsSync(objectKey)) {
199
+ return null;
200
+ }
201
+ const fileStat = fs_extra_1.default.statSync(objectKey);
202
+ const objectName = (0, path_1.basename)(objectKey);
203
+ const directorySuffixes = fileStat.isDirectory() ? '/' : '';
204
+ const key = (0, path_1.join)(options.key, directorySuffixes);
205
+ return {
206
+ key,
207
+ name: (0, path_1.join)(objectName, directorySuffixes),
208
+ isDir: fileStat.isDirectory(),
209
+ size: fileStat.size,
210
+ lastModified: new Date(fileStat.mtime).getTime(),
211
+ editable: core_1.Space.editable(key),
212
+ mimeType: mime_types_1.default.lookup(objectName) || 'unknown',
213
+ };
214
+ });
215
+ }
216
+ writeAsOwner(key, data) {
217
+ return __awaiter(this, void 0, void 0, function* () {
218
+ const objectPath = (0, path_1.join)(this.options.root, key);
219
+ if (objectPath.endsWith('/')) {
220
+ // 这是一个文件夹
221
+ yield fs_extra_1.default.ensureDir(objectPath);
222
+ }
223
+ else if ((0, lodash_1.isString)(data) || (0, lodash_1.isBuffer)(data)) {
224
+ yield fs_extra_1.default.outputFile(objectPath, data);
225
+ }
226
+ else if (data instanceof stream_1.Stream || data instanceof stream_1.Readable || (0, lodash_1.isFunction)(data === null || data === void 0 ? void 0 : data.pipe)) {
227
+ fs_extra_1.default.ensureDirSync((0, path_1.dirname)(objectPath));
228
+ yield (0, read_stream_to_file_1.readStreamToFile)(data, fs_extra_1.default.createWriteStream(objectPath));
229
+ }
230
+ else {
231
+ throw new Error('Data is unsupported format, expected data to be one of: string | Buffer | ReadableStream.');
232
+ }
233
+ });
234
+ }
235
+ deleteAsOwner(key) {
236
+ return __awaiter(this, void 0, void 0, function* () {
237
+ return fs_extra_1.default.remove((0, path_1.join)(this.options.root, key));
238
+ });
239
+ }
240
+ readAsOwner(key) {
241
+ return __awaiter(this, void 0, void 0, function* () {
242
+ // FIXME: @yejianchao 应该可以refactor,但是我还需要测试一下
243
+ return fs_extra_1.default.readFile((0, path_1.join)(this.options.root, key)).then((data) => stream_1.Readable.from(data));
244
+ });
245
+ }
246
+ existsAsOwner(key) {
247
+ return __awaiter(this, void 0, void 0, function* () {
248
+ return fs_extra_1.default.existsSync((0, path_1.join)(this.options.root, key));
249
+ });
250
+ }
251
+ }
252
+ exports.FsSpaceOperator = FsSpaceOperator;
253
+ FsSpaceOperator.APPS = 'apps';
@@ -0,0 +1,6 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import { Stream } from 'stream';
4
+ import { WriteStream } from 'fs';
5
+ declare function readStreamToFile(readStream: Stream, writeStream: WriteStream): Promise<void>;
6
+ export { readStreamToFile };
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readStreamToFile = void 0;
4
+ const core_1 = require("@did-space/core");
5
+ function readStreamToFile(readStream, writeStream) {
6
+ return new Promise((resolve, reject) => {
7
+ writeStream.on('data', () => {
8
+ return resolve();
9
+ });
10
+ writeStream.on('finish', () => {
11
+ return resolve();
12
+ });
13
+ writeStream.on('error', (error) => {
14
+ core_1.logger.error('readStreamToFile', error.message);
15
+ return reject(error);
16
+ });
17
+ readStream.pipe(writeStream);
18
+ });
19
+ }
20
+ exports.readStreamToFile = readStreamToFile;
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "@did-space/fs-driver",
3
+ "version": "0.2.5",
4
+ "publishConfig": {
5
+ "access": "public"
6
+ },
7
+ "description": "Decentralized file space managed by DID",
8
+ "author": "linchen1987 <linchen.1987@foxmail.com>",
9
+ "homepage": "",
10
+ "license": "ISC",
11
+ "main": "dist/index.js",
12
+ "typings": "dist/index.d.ts",
13
+ "files": [
14
+ "dist"
15
+ ],
16
+ "scripts": {
17
+ "lint": "eslint src tests",
18
+ "lint:fix": "npm run lint -- --fix",
19
+ "test": "jest --forceExit --detectOpenHandles --passWithNoTests",
20
+ "coverage": "yarn test -- --coverage",
21
+ "prebuild": "rm -fr dist",
22
+ "build": "tsc",
23
+ "build:watch": "npm run build -- --watch",
24
+ "pre-commit": "lint-staged",
25
+ "verify": "npm run lint && npm run test && npm run build"
26
+ },
27
+ "lint-staged": {
28
+ "**/*.{js,ts}": [
29
+ "npm run lint",
30
+ "npm run test",
31
+ "git add ."
32
+ ]
33
+ },
34
+ "dependencies": {
35
+ "@arcblock/did": "^1.18.57",
36
+ "@arcblock/jwt": "^1.18.57",
37
+ "@did-space/core": "0.2.5",
38
+ "@ocap/mcrypto": "^1.18.57",
39
+ "@ocap/wallet": "^1.18.57",
40
+ "filehound": "^1.17.6",
41
+ "fs-extra": "^10.1.0",
42
+ "hasha": "^5.2.2",
43
+ "js-yaml": "^4.1.0",
44
+ "json-stable-stringify": "^1.0.1",
45
+ "lodash": "^4.17.21",
46
+ "mime-types": "^2.1.35"
47
+ },
48
+ "devDependencies": {
49
+ "@arcblock/eslint-config-ts": "^0.2.3",
50
+ "@types/fs-extra": "^9.0.13",
51
+ "@types/jest": "^28.1.5",
52
+ "@types/js-yaml": "^4.0.5",
53
+ "@types/json-stable-stringify": "^1.0.34",
54
+ "@types/lodash": "^4.14.191",
55
+ "@types/mime-types": "^2.1.1",
56
+ "@types/node": "15.12.2",
57
+ "@typescript-eslint/eslint-plugin": "^5.30.6",
58
+ "eslint": "^8.19.0",
59
+ "lint-staged": "^13.0.3",
60
+ "ts-jest": "^28.0.6",
61
+ "typescript": "^4.9.5"
62
+ },
63
+ "gitHead": "4d49e73817f610375982509ba8f250ba34e16efb"
64
+ }