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