fsd-fs 0.14.0 → 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.
Files changed (3) hide show
  1. package/lib/index.js +43 -42
  2. package/package.json +4 -5
  3. package/LICENSE +0 -21
package/lib/index.js CHANGED
@@ -1,16 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const os = require("os");
4
- const Path = require("path");
5
- const fs = require("fs");
6
- const isStream = require("is-stream");
3
+ const tslib_1 = require("tslib");
4
+ const os_1 = tslib_1.__importDefault(require("os"));
5
+ const path_1 = tslib_1.__importDefault(require("path"));
6
+ const fs_1 = tslib_1.__importDefault(require("fs"));
7
+ const is_stream_1 = tslib_1.__importDefault(require("is-stream"));
7
8
  const glob_1 = require("glob");
8
- const mapLimit = require("async/mapLimit");
9
- const Debugger = require("debug");
10
- const debug = Debugger('fsd-fs');
9
+ const mapLimit_1 = tslib_1.__importDefault(require("async/mapLimit"));
10
+ const debug_1 = tslib_1.__importDefault(require("debug"));
11
+ const debug = (0, debug_1.default)('fsd-fs');
11
12
  async function getStat(path) {
12
13
  try {
13
- return await fs.promises.stat(path);
14
+ return await fs_1.default.promises.stat(path);
14
15
  }
15
16
  catch (_e) {
16
17
  return null;
@@ -25,7 +26,7 @@ class FSAdapter {
25
26
  urlPrefix: '',
26
27
  root: '/',
27
28
  mode: 0o666,
28
- tmpdir: os.tmpdir()
29
+ tmpdir: os_1.default.tmpdir()
29
30
  }, options);
30
31
  let { urlPrefix } = this._options;
31
32
  if (urlPrefix.endsWith('/')) {
@@ -36,13 +37,13 @@ class FSAdapter {
36
37
  async append(path, data) {
37
38
  debug('append %s', path);
38
39
  let { root, mode } = this._options;
39
- let p = Path.join(root, path);
40
- if (isStream.readable(data)) {
40
+ let p = path_1.default.join(root, path);
41
+ if (is_stream_1.default.readable(data)) {
41
42
  let stream = data;
42
43
  await new Promise((resolve, reject) => {
43
- fs.stat(p, (error, stat) => {
44
+ fs_1.default.stat(p, (error, stat) => {
44
45
  let start = error ? 0 : stat.size;
45
- let writeStream = fs.createWriteStream(p, {
46
+ let writeStream = fs_1.default.createWriteStream(p, {
46
47
  flags: 'a',
47
48
  mode,
48
49
  start
@@ -52,33 +53,33 @@ class FSAdapter {
52
53
  });
53
54
  return;
54
55
  }
55
- await fs.promises.appendFile(p, data, { mode });
56
+ await fs_1.default.promises.appendFile(p, data, { mode });
56
57
  }
57
58
  async createReadStream(path, options) {
58
59
  debug('createReadStream %s options: %o', path, options);
59
- let p = Path.join(this._options.root, path);
60
- return fs.createReadStream(p, options);
60
+ let p = path_1.default.join(this._options.root, path);
61
+ return fs_1.default.createReadStream(p, options);
61
62
  }
62
63
  async createWriteStream(path, options) {
63
64
  debug('createWriteStream %s', path);
64
65
  let p;
65
66
  if (path.startsWith('task://')) {
66
- p = Path.join(this._options.tmpdir, path.replace('task://', ''));
67
+ p = path_1.default.join(this._options.tmpdir, path.replace('task://', ''));
67
68
  }
68
69
  else {
69
- p = Path.join(this._options.root, path);
70
+ p = path_1.default.join(this._options.root, path);
70
71
  }
71
- return fs.createWriteStream(p, options);
72
+ return fs_1.default.createWriteStream(p, options);
72
73
  }
73
74
  async unlink(path) {
74
75
  debug('unlink %s', path);
75
- let p = Path.join(this._options.root, path);
76
- await fs.promises.rm(p, { recursive: true, force: true });
76
+ let p = path_1.default.join(this._options.root, path);
77
+ await fs_1.default.promises.rm(p, { recursive: true, force: true });
77
78
  }
78
79
  async mkdir(path, recursive) {
79
80
  debug('mkdir %s', path);
80
- let fsPath = Path.join(this._options.root, path);
81
- await fs.promises.mkdir(fsPath, { recursive });
81
+ let fsPath = path_1.default.join(this._options.root, path);
82
+ await fs_1.default.promises.mkdir(fsPath, { recursive });
82
83
  }
83
84
  async readdir(path, recursion) {
84
85
  debug('readdir %s', path);
@@ -86,13 +87,13 @@ class FSAdapter {
86
87
  recursion = '**/*';
87
88
  }
88
89
  let pattern = recursion || '*';
89
- let p = Path.join(this._options.root, path);
90
+ let p = path_1.default.join(this._options.root, path);
90
91
  let files = await (0, glob_1.glob)(pattern, {
91
92
  cwd: p
92
93
  });
93
94
  files.reverse();
94
- return await mapLimit(files, 20, async (name) => {
95
- let filePath = Path.join(p, name);
95
+ return await (0, mapLimit_1.default)(files, 20, async (name) => {
96
+ let filePath = path_1.default.join(p, name);
96
97
  let stat = await getStat(filePath);
97
98
  let isDir = stat.isDirectory();
98
99
  return {
@@ -112,44 +113,44 @@ class FSAdapter {
112
113
  async copy(path, dest) {
113
114
  debug('copy %s to %s', path, dest);
114
115
  const { root } = this._options;
115
- let from = Path.join(root, path);
116
- let to = Path.join(root, dest);
116
+ let from = path_1.default.join(root, path);
117
+ let to = path_1.default.join(root, dest);
117
118
  if (!(await getStat(from)))
118
119
  throw new Error(`source file '${path}' is not exists!`);
119
- await fs.promises.cp(from, to, { recursive: true, force: true });
120
+ await fs_1.default.promises.cp(from, to, { recursive: true, force: true });
120
121
  }
121
122
  async rename(path, dest) {
122
123
  debug('rename %s to %s', path, dest);
123
- let from = Path.join(this._options.root, path);
124
- let to = Path.join(this._options.root, dest);
125
- await fs.promises.rename(from, to);
124
+ let from = path_1.default.join(this._options.root, path);
125
+ let to = path_1.default.join(this._options.root, dest);
126
+ await fs_1.default.promises.rename(from, to);
126
127
  }
127
128
  async exists(path) {
128
129
  debug('check exists %s', path);
129
- let p = Path.join(this._options.root, path);
130
+ let p = path_1.default.join(this._options.root, path);
130
131
  return !!(await getStat(p));
131
132
  }
132
133
  async isFile(path) {
133
134
  debug('check is file %s', path);
134
- let p = Path.join(this._options.root, path);
135
+ let p = path_1.default.join(this._options.root, path);
135
136
  let stat = await getStat(p);
136
137
  return stat?.isFile();
137
138
  }
138
139
  async isDirectory(path) {
139
140
  debug('check is directory %s', path);
140
- let p = Path.join(this._options.root, path);
141
+ let p = path_1.default.join(this._options.root, path);
141
142
  let stat = await getStat(p);
142
143
  return stat?.isDirectory();
143
144
  }
144
145
  async size(path) {
145
146
  debug('get file size %s', path);
146
- let p = Path.join(this._options.root, path);
147
+ let p = path_1.default.join(this._options.root, path);
147
148
  let stat = await getStat(p);
148
149
  return stat.size;
149
150
  }
150
151
  async lastModified(path) {
151
152
  debug('get file lastModified %s', path);
152
- let p = Path.join(this._options.root, path);
153
+ let p = path_1.default.join(this._options.root, path);
153
154
  let stat = await getStat(p);
154
155
  return stat.mtime;
155
156
  }
@@ -178,27 +179,27 @@ class FSAdapter {
178
179
  for (let part of parts) {
179
180
  if (!part.startsWith('part://'))
180
181
  throw new Error(`${part} is not a part file`);
181
- let partPath = Path.join(this._options.tmpdir, part.replace('part://', ''));
182
+ let partPath = path_1.default.join(this._options.tmpdir, part.replace('part://', ''));
182
183
  let stat = await getStat(partPath);
183
184
  if (!stat)
184
185
  throw new Error(`part file ${part} is not exists`);
185
186
  partPaths.push({ file: partPath, size: stat.size });
186
187
  }
187
- let p = Path.join(this._options.root, path);
188
+ let p = path_1.default.join(this._options.root, path);
188
189
  let start = 0;
189
190
  for (let info of partPaths) {
190
- let writeStream = fs.createWriteStream(p, {
191
+ let writeStream = fs_1.default.createWriteStream(p, {
191
192
  flags: 'a',
192
193
  start
193
194
  });
194
- let stream = fs.createReadStream(info.file);
195
+ let stream = fs_1.default.createReadStream(info.file);
195
196
  await new Promise((resolve, reject) => {
196
197
  stream.pipe(writeStream).on('close', resolve).on('error', reject);
197
198
  });
198
199
  start += info.size;
199
200
  writeStream.close();
200
201
  }
201
- partPaths.forEach((info) => fs.promises.rm(info.file, { force: true }));
202
+ partPaths.forEach((info) => fs_1.default.promises.rm(info.file, { force: true }));
202
203
  }
203
204
  }
204
205
  exports.default = FSAdapter;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fsd-fs",
3
- "version": "0.14.0",
3
+ "version": "0.14.1",
4
4
  "description": "File system adapter for fsd",
5
5
  "main": "lib/index.js",
6
6
  "types": "index.d.ts",
@@ -13,9 +13,8 @@
13
13
  "license": "MIT",
14
14
  "dependencies": {
15
15
  "async": "*",
16
- "debug": "^4.4.0",
17
- "glob": "^10.4.5",
16
+ "debug": "^4.4.3",
17
+ "glob": "^10.5.0",
18
18
  "is-stream": "^2.0.1"
19
- },
20
- "gitHead": "74e32bf47242909f040eb6012dda56e5c5a668a0"
19
+ }
21
20
  }
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.