fsd 0.13.1 → 0.14.1
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/file.js +17 -18
- package/lib/fsd.js +3 -2
- package/package.json +3 -4
- package/LICENSE +0 -21
package/lib/file.js
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
5
|
+
const slash_1 = tslib_1.__importDefault(require("slash"));
|
|
6
|
+
const debug_1 = tslib_1.__importDefault(require("debug"));
|
|
7
|
+
const is_stream_1 = tslib_1.__importDefault(require("is-stream"));
|
|
7
8
|
const stream_1 = require("stream");
|
|
8
|
-
const debug =
|
|
9
|
+
const debug = (0, debug_1.default)('fsd');
|
|
9
10
|
class FSDFile {
|
|
10
|
-
constructor(
|
|
11
|
-
|
|
12
|
-
if (!path)
|
|
11
|
+
constructor(pathOrFile, adapter, metadata) {
|
|
12
|
+
if (!pathOrFile)
|
|
13
13
|
throw new Error('FSD File must initialize with path');
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
14
|
+
debug('initialize file %s', pathOrFile);
|
|
15
|
+
let path = typeof pathOrFile === 'object' ? pathOrFile.path : pathOrFile;
|
|
17
16
|
if (path[0] !== '/') {
|
|
18
17
|
path = `/${path}`;
|
|
19
18
|
}
|
|
@@ -21,7 +20,7 @@ class FSDFile {
|
|
|
21
20
|
this._adapter = adapter;
|
|
22
21
|
this.needEnsureDir = adapter.needEnsureDir;
|
|
23
22
|
this.path = path;
|
|
24
|
-
let info =
|
|
23
|
+
let info = path_1.default.parse(path);
|
|
25
24
|
this.dir = info.dir;
|
|
26
25
|
if (this.dir !== '/') {
|
|
27
26
|
this.dir += '/';
|
|
@@ -84,7 +83,7 @@ class FSDFile {
|
|
|
84
83
|
this._lastModified = null;
|
|
85
84
|
let stream = await this._adapter.createWriteStream(this.path);
|
|
86
85
|
if (stream.promise) {
|
|
87
|
-
if (
|
|
86
|
+
if (is_stream_1.default.readable(data)) {
|
|
88
87
|
data.pipe(stream);
|
|
89
88
|
}
|
|
90
89
|
else {
|
|
@@ -96,7 +95,7 @@ class FSDFile {
|
|
|
96
95
|
await new Promise((resolve, reject) => {
|
|
97
96
|
stream.on('error', reject);
|
|
98
97
|
stream.on('finish', resolve);
|
|
99
|
-
if (
|
|
98
|
+
if (is_stream_1.default.readable(data)) {
|
|
100
99
|
data.pipe(stream);
|
|
101
100
|
}
|
|
102
101
|
else {
|
|
@@ -142,7 +141,7 @@ class FSDFile {
|
|
|
142
141
|
}
|
|
143
142
|
let files = await this._adapter.readdir(this.path, recursion);
|
|
144
143
|
return files.map(({ name, metadata }) => {
|
|
145
|
-
let path =
|
|
144
|
+
let path = (0, slash_1.default)(path_1.default.join(this.path, name));
|
|
146
145
|
return new FSDFile(path, this._adapter, metadata);
|
|
147
146
|
});
|
|
148
147
|
}
|
|
@@ -152,8 +151,8 @@ class FSDFile {
|
|
|
152
151
|
}
|
|
153
152
|
async copy(dest) {
|
|
154
153
|
debug('copy %s to %s', this.path, dest);
|
|
155
|
-
if (!
|
|
156
|
-
dest =
|
|
154
|
+
if (!path_1.default.isAbsolute(dest)) {
|
|
155
|
+
dest = (0, slash_1.default)(path_1.default.join(path_1.default.dirname(this.path), dest));
|
|
157
156
|
}
|
|
158
157
|
if (dest === this.path) {
|
|
159
158
|
throw new Error('copy failed, dest path should not equal to source path');
|
|
@@ -229,7 +228,7 @@ class FSDFile {
|
|
|
229
228
|
if (!task.startsWith('task:'))
|
|
230
229
|
throw new Error('Invalid task link');
|
|
231
230
|
let stream;
|
|
232
|
-
if (
|
|
231
|
+
if (is_stream_1.default.readable(data)) {
|
|
233
232
|
stream = data;
|
|
234
233
|
}
|
|
235
234
|
else {
|
package/lib/fsd.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
3
|
+
exports.default = FSD;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const file_1 = tslib_1.__importDefault(require("./file"));
|
|
4
6
|
function FSD(options) {
|
|
5
7
|
function fsd(path) {
|
|
6
8
|
return new file_1.default(path, options.adapter);
|
|
@@ -8,4 +10,3 @@ function FSD(options) {
|
|
|
8
10
|
fsd.adapter = options.adapter;
|
|
9
11
|
return fsd;
|
|
10
12
|
}
|
|
11
|
-
exports.default = FSD;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fsd",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.1",
|
|
4
4
|
"description": "General file system driver for Node.js",
|
|
5
5
|
"main": "lib/fsd.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -12,9 +12,8 @@
|
|
|
12
12
|
"author": "Liang <liang@miaomo.cc> (https://github.com/liangxingchen)",
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"debug": "^4.3
|
|
15
|
+
"debug": "^4.4.3",
|
|
16
16
|
"is-stream": "^2.0.1",
|
|
17
17
|
"slash": "^3.0.0"
|
|
18
|
-
}
|
|
19
|
-
"gitHead": "12ff02bfc634ba84c771ca433d33aae2dc881436"
|
|
18
|
+
}
|
|
20
19
|
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2023 郑州渺漠信息科技有限公司
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, destribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|