vvvfs 0.1.5 → 0.1.6
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 +210 -34
- package/index.ts +213 -0
- package/package.json +33 -33
- package/types/index.d.ts +108 -0
package/README.md
CHANGED
|
@@ -31,7 +31,7 @@ const VVVFS = require("vvvfs"); // CommonJS
|
|
|
31
31
|
|
|
32
32
|
```javascript
|
|
33
33
|
const vvvfs = new VVVFS("vvvfs", {
|
|
34
|
-
|
|
34
|
+
throwError: true, // 设置为true后,操作文件失败时,不会返回false,而是会抛出错误
|
|
35
35
|
}); // 创建一个名为vvvfs的虚拟文件系统
|
|
36
36
|
```
|
|
37
37
|
|
|
@@ -40,34 +40,40 @@ const vvvfs = new VVVFS("vvvfs", {
|
|
|
40
40
|
```javascript
|
|
41
41
|
// 所有操作都是异步的
|
|
42
42
|
(async function () {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
43
|
+
await vvvfs.reset(); // 重置文件系统
|
|
44
|
+
await vvvfs.init("UserName"); // 初始化文件系统
|
|
45
|
+
vvvfs.watch("/home/user/Desktop/test.txt", (type) => {
|
|
46
|
+
console.log(type); // 打印文件操作的类型
|
|
47
|
+
return true; // 返回true或false,表示是否取消该操作
|
|
48
|
+
});
|
|
49
|
+
await vvvfs.lock("/home/user/Desktop/test.txt"); // 锁定文件,防止其他代码访问该文件
|
|
50
|
+
await vvvfs.unlock("/home/user/Desktop/test.txt"); // 解锁文件
|
|
51
|
+
await vvvfs.createDir("/home/user/Desktop"); // 创建目录,返回true和false
|
|
52
|
+
await vvvfs.writeText("/home/user/Desktop/test.txt", "Hello World!"); // 写入文本文件,写入文件还包括write(path: string, content: Blob)和writeJson(path: string, content: Record<string, any>)方法,返回true和false
|
|
53
|
+
await vvvfs.appendText("/home/user/Desktop/test.txt", "Hello World!"); // 追加文本文件,返回true和false
|
|
54
|
+
console.log(await vvvfs.readText("/home/user/Desktop/test.txt")); // 读取文本文件,读取文件还包括read(path: string): Blob | null和readJson(path: string): Record<string, any> | null方法
|
|
55
|
+
console.log(await vvvfs.readChunkText("/home/user/Desktop/test.txt", 0, 5)); // 读取文件块,返回string | null
|
|
56
|
+
await vvvfs.delete("/home/user/Desktop/test.txt"); // 删除文件,返回true和false
|
|
57
|
+
if (await vvvfs.exists("/home/user/Desktop")) {
|
|
58
|
+
// 判断文件或目录是否存在
|
|
59
|
+
}
|
|
60
|
+
console.log(await vvvfs.list("/home/user/Desktop")); // 列出目录下的文件,返回string[] | null
|
|
61
|
+
if (await vvvfs.isDir("/home/user/Desktop")) {
|
|
62
|
+
// 判断是否为目录
|
|
63
|
+
}
|
|
64
|
+
if (await vvvfs.isFile("/home/user/Desktop/test.txt")) {
|
|
65
|
+
// 判断是否为文件
|
|
66
|
+
}
|
|
67
|
+
await vvvfs.rename("/home/user/Desktop/test.txt", "test2.txt"); // 重命名文件,返回true和false
|
|
68
|
+
await vvvfs.move(
|
|
69
|
+
"/home/user/Desktop/test2.txt",
|
|
70
|
+
"/home/user/Desktop/test.txt",
|
|
71
|
+
); // 移动文件,返回true和false
|
|
72
|
+
await vvvfs.copy(
|
|
73
|
+
"/home/user/Desktop/test.txt",
|
|
74
|
+
"/home/user/Desktop/test2.txt",
|
|
75
|
+
); // 复制文件,返回true和false
|
|
76
|
+
await vvvfs.search("/home/user/Desktop", "test.txt"); // 搜索文件,返回string[] | null
|
|
71
77
|
})();
|
|
72
78
|
```
|
|
73
79
|
|
|
@@ -75,17 +81,21 @@ const vvvfs = new VVVFS("vvvfs", {
|
|
|
75
81
|
|
|
76
82
|
```javascript
|
|
77
83
|
(async function () {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
84
|
+
const file = new VVVFS.File("/home/user/Desktop/test.txt");
|
|
85
|
+
// file.options.throwError = true;
|
|
86
|
+
await file.writeText("Hello World!");
|
|
87
|
+
console.log(await file.readText());
|
|
88
|
+
await file.delete();
|
|
83
89
|
})();
|
|
84
90
|
// 用法与 vvvfs 相当
|
|
85
91
|
```
|
|
86
92
|
|
|
87
93
|
## 更新日志
|
|
88
94
|
|
|
95
|
+
### 0.1.6
|
|
96
|
+
|
|
97
|
+
- 新增 `VVVFS.path` ,用法与 NodeJS 的 `path` 模块类似。
|
|
98
|
+
|
|
89
99
|
### 0.1.5
|
|
90
100
|
|
|
91
101
|
- 重新 `lock` 和 `unlock` 方法
|
|
@@ -149,3 +159,169 @@ const vvvfs = new VVVFS("vvvfs", {
|
|
|
149
159
|
### 0.0.1
|
|
150
160
|
|
|
151
161
|
- 发布正式版
|
|
162
|
+
|
|
163
|
+
---
|
|
164
|
+
|
|
165
|
+
# English
|
|
166
|
+
|
|
167
|
+
# VVVFS
|
|
168
|
+
|
|
169
|
+
A lightweight and simple Linux virtual file system in the browser, based on IndexedDB, built with Dexie.js
|
|
170
|
+
|
|
171
|
+
## Quick Start
|
|
172
|
+
|
|
173
|
+
1. Install the dependency
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
npm install vvvfs
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
2. Import
|
|
180
|
+
|
|
181
|
+
```javascript
|
|
182
|
+
import VVVFS from "vvvfs"; // ES6
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
```javascript
|
|
186
|
+
const VVVFS = require("vvvfs"); // CommonJS
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
```html
|
|
190
|
+
<script src="dist/vvvfs.min.js"></script>
|
|
191
|
+
<script src="https://cdn.jsdelivr.net/npm/vvvfs@latest/dist/vvvfs.min.js"></script>
|
|
192
|
+
<script src="https://unpkg.com/vvvfs@latest/dist/vvvfs.min.js"></script>
|
|
193
|
+
<!-- Browser -->
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
3. Initialize
|
|
197
|
+
|
|
198
|
+
```javascript
|
|
199
|
+
const vvvfs = new VVVFS("vvvfs", {
|
|
200
|
+
throwError: true, // When set to true, failed file operations throw an error instead of returning false
|
|
201
|
+
}); // Create a virtual file system named vvvfs
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
4. Usage
|
|
205
|
+
|
|
206
|
+
```javascript
|
|
207
|
+
// All operations are asynchronous
|
|
208
|
+
(async function () {
|
|
209
|
+
await vvvfs.reset(); // Reset the file system
|
|
210
|
+
await vvvfs.init("UserName"); // Initialize the file system
|
|
211
|
+
vvvfs.watch("/home/user/Desktop/test.txt", (type) => {
|
|
212
|
+
console.log(type); // Log the type of the file operation
|
|
213
|
+
return true; // Return true or false to indicate whether to cancel the operation
|
|
214
|
+
});
|
|
215
|
+
await vvvfs.lock("/home/user/Desktop/test.txt"); // Lock the file to prevent other code from accessing it
|
|
216
|
+
await vvvfs.unlock("/home/user/Desktop/test.txt"); // Unlock the file
|
|
217
|
+
await vvvfs.createDir("/home/user/Desktop"); // Create a directory, returns true and false
|
|
218
|
+
await vvvfs.writeText("/home/user/Desktop/test.txt", "Hello World!"); // Write a text file. Writing also includes write(path: string, content: Blob) and writeJson(path: string, content: Record<string, any>), returns true and false
|
|
219
|
+
await vvvfs.appendText("/home/user/Desktop/test.txt", "Hello World!"); // Append text to a file, returns true and false
|
|
220
|
+
console.log(await vvvfs.readText("/home/user/Desktop/test.txt")); // Read a text file. Reading also includes read(path: string): Blob | null and readJson(path: string): Record<string, any> | null
|
|
221
|
+
console.log(await vvvfs.readChunkText("/home/user/Desktop/test.txt", 0, 5)); // Read a file chunk, returns string | null
|
|
222
|
+
await vvvfs.delete("/home/user/Desktop/test.txt"); // Delete a file, returns true and false
|
|
223
|
+
if (await vvvfs.exists("/home/user/Desktop")) {
|
|
224
|
+
// Check whether a file or directory exists
|
|
225
|
+
}
|
|
226
|
+
console.log(await vvvfs.list("/home/user/Desktop")); // List the files in a directory, returns string[] | null
|
|
227
|
+
if (await vvvfs.isDir("/home/user/Desktop")) {
|
|
228
|
+
// Check whether it is a directory
|
|
229
|
+
}
|
|
230
|
+
if (await vvvfs.isFile("/home/user/Desktop/test.txt")) {
|
|
231
|
+
// Check whether it is a file
|
|
232
|
+
}
|
|
233
|
+
await vvvfs.rename("/home/user/Desktop/test.txt", "test2.txt"); // Rename a file, returns true and false
|
|
234
|
+
await vvvfs.move(
|
|
235
|
+
"/home/user/Desktop/test2.txt",
|
|
236
|
+
"/home/user/Desktop/test.txt",
|
|
237
|
+
); // Move a file, returns true and false
|
|
238
|
+
await vvvfs.copy(
|
|
239
|
+
"/home/user/Desktop/test.txt",
|
|
240
|
+
"/home/user/Desktop/test2.txt",
|
|
241
|
+
); // Copy a file, returns true and false
|
|
242
|
+
await vvvfs.search("/home/user/Desktop", "test.txt"); // Search for files, returns string[] | null
|
|
243
|
+
})();
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
Using the `VVVFS.File` class:
|
|
247
|
+
|
|
248
|
+
```javascript
|
|
249
|
+
(async function () {
|
|
250
|
+
const file = new VVVFS.File("/home/user/Desktop/test.txt");
|
|
251
|
+
// file.options.throwError = true;
|
|
252
|
+
await file.writeText("Hello World!");
|
|
253
|
+
console.log(await file.readText());
|
|
254
|
+
await file.delete();
|
|
255
|
+
})();
|
|
256
|
+
// The usage is equivalent to vvvfs
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
## Changelog
|
|
260
|
+
|
|
261
|
+
### 0.1.6
|
|
262
|
+
|
|
263
|
+
- Added `VVVFS.path`, which works in a similar way to the `path` module in NodeJS.
|
|
264
|
+
|
|
265
|
+
### 0.1.5
|
|
266
|
+
|
|
267
|
+
- Redesigned the `lock` and `unlock` methods
|
|
268
|
+
|
|
269
|
+
### 0.1.4
|
|
270
|
+
|
|
271
|
+
- Optimized the code with AI
|
|
272
|
+
|
|
273
|
+
### 0.1.3
|
|
274
|
+
|
|
275
|
+
- Added the `lock` and `unlock` methods, which can lock files to prevent other code from accessing them
|
|
276
|
+
|
|
277
|
+
### 0.1.2
|
|
278
|
+
|
|
279
|
+
- Added the `readChunk` and `readChunkText` methods for reading file chunks
|
|
280
|
+
|
|
281
|
+
### 0.1.1
|
|
282
|
+
|
|
283
|
+
- Added the `append` and `appendText` methods for appending content
|
|
284
|
+
|
|
285
|
+
### 0.1.0
|
|
286
|
+
|
|
287
|
+
- Fixed `init` rewriting existing files and directories when initialized repeatedly
|
|
288
|
+
|
|
289
|
+
### 0.0.9
|
|
290
|
+
|
|
291
|
+
- Updated the `watch` method: while watching, returning `true` cancels the operation
|
|
292
|
+
|
|
293
|
+
### 0.0.8
|
|
294
|
+
|
|
295
|
+
- Added the `watch` method (this is an experimental feature and may change in the future)
|
|
296
|
+
|
|
297
|
+
### 0.0.7
|
|
298
|
+
|
|
299
|
+
- Optimized a bit with AI
|
|
300
|
+
|
|
301
|
+
### 0.0.6
|
|
302
|
+
|
|
303
|
+
- Added the `dbname` and `options` properties to the `VVVFS.File` class
|
|
304
|
+
- Added the `defaultDBName` property to `VVVFS`
|
|
305
|
+
|
|
306
|
+
### 0.0.5
|
|
307
|
+
|
|
308
|
+
- Added the `VVVFS.File` class
|
|
309
|
+
|
|
310
|
+
### 0.0.4
|
|
311
|
+
|
|
312
|
+
- Fixed IndexedDB spamming a bunch of warnings
|
|
313
|
+
- Fixed a bug in `search`
|
|
314
|
+
|
|
315
|
+
### 0.0.3
|
|
316
|
+
|
|
317
|
+
- Added maximum length limits: 4096 characters for full paths and 255 characters for file names
|
|
318
|
+
- Added the `init` method for initializing Linux files and directories
|
|
319
|
+
- Fixed a bug where `list` returned an empty string (the root directory itself) in the array when listing the root directory
|
|
320
|
+
|
|
321
|
+
### 0.0.2
|
|
322
|
+
|
|
323
|
+
- Added the `throwError` option, which defaults to `false`
|
|
324
|
+
|
|
325
|
+
### 0.0.1
|
|
326
|
+
|
|
327
|
+
- Initial release
|
package/index.ts
CHANGED
|
@@ -274,6 +274,215 @@ class VVVFSFile {
|
|
|
274
274
|
}
|
|
275
275
|
}
|
|
276
276
|
|
|
277
|
+
/**
|
|
278
|
+
* path类(类似于NodeJS中的path模块)
|
|
279
|
+
*/
|
|
280
|
+
class Path {
|
|
281
|
+
/**
|
|
282
|
+
* 路径分隔符
|
|
283
|
+
*/
|
|
284
|
+
static readonly sep = "/";
|
|
285
|
+
/**
|
|
286
|
+
* 环境变量PATH的分隔符
|
|
287
|
+
*/
|
|
288
|
+
static readonly delimiter = ":";
|
|
289
|
+
/**
|
|
290
|
+
* 内部存储的路径
|
|
291
|
+
*/
|
|
292
|
+
private _path: string;
|
|
293
|
+
/**
|
|
294
|
+
* 构造函数
|
|
295
|
+
* @param paths 路径片段
|
|
296
|
+
*/
|
|
297
|
+
constructor(...paths: string[]) {
|
|
298
|
+
this._path = Path.resolve(...paths);
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* 获取路径
|
|
302
|
+
*/
|
|
303
|
+
get path() {
|
|
304
|
+
return this._path;
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* 设置路径
|
|
308
|
+
* @param path 路径
|
|
309
|
+
*/
|
|
310
|
+
set path(path: string) {
|
|
311
|
+
this._path = Path.resolve(path);
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* 获取文件名
|
|
315
|
+
*/
|
|
316
|
+
get name() {
|
|
317
|
+
return Path.basename(this._path);
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* 获取文件所在目录
|
|
321
|
+
*/
|
|
322
|
+
get parent() {
|
|
323
|
+
return Path.dirname(this._path);
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* 获取文件扩展名
|
|
327
|
+
*/
|
|
328
|
+
get ext() {
|
|
329
|
+
return Path.extname(this._path);
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* 获取根目录("/"或"")
|
|
333
|
+
*/
|
|
334
|
+
get root() {
|
|
335
|
+
return Path.parse(this._path).root;
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* 判断路径是否为绝对路径
|
|
339
|
+
*/
|
|
340
|
+
isAbsolute() {
|
|
341
|
+
return Path.isAbsolute(this._path);
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* 合并路径
|
|
345
|
+
* @param paths 路径片段
|
|
346
|
+
*/
|
|
347
|
+
join(...paths: string[]) {
|
|
348
|
+
return Path.join(this._path, ...paths);
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* 转换为字符串
|
|
352
|
+
*/
|
|
353
|
+
toString() {
|
|
354
|
+
return this._path;
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* 合并路径
|
|
358
|
+
* @param paths 路径片段
|
|
359
|
+
*/
|
|
360
|
+
static join(...paths: string[]) {
|
|
361
|
+
return joinPath(...paths);
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* 解析路径为绝对路径
|
|
365
|
+
* @param paths 路径片段
|
|
366
|
+
*/
|
|
367
|
+
static resolve(...paths: string[]) {
|
|
368
|
+
return paths.length === 0 ? "/" : joinPath(...paths);
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* 规范化路径(清除"."、解析"..")
|
|
372
|
+
* @param path 路径
|
|
373
|
+
*/
|
|
374
|
+
static normalize(path: string) {
|
|
375
|
+
if (path.length === 0) return ".";
|
|
376
|
+
const isAbsolute = path.startsWith("/");
|
|
377
|
+
const trailingSlash = path.length > 1 && path.endsWith("/");
|
|
378
|
+
const stack: string[] = [];
|
|
379
|
+
for (const part of path.split("/")) {
|
|
380
|
+
if (part === "" || part === ".") {
|
|
381
|
+
continue;
|
|
382
|
+
} else if (part === "..") {
|
|
383
|
+
if (stack.length > 0 && stack[stack.length - 1] !== "..") {
|
|
384
|
+
stack.pop();
|
|
385
|
+
} else if (!isAbsolute) {
|
|
386
|
+
stack.push("..");
|
|
387
|
+
}
|
|
388
|
+
} else {
|
|
389
|
+
stack.push(part);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
let result = stack.join("/");
|
|
393
|
+
if (isAbsolute) {
|
|
394
|
+
result = "/" + result;
|
|
395
|
+
} else if (result.length === 0) {
|
|
396
|
+
result = ".";
|
|
397
|
+
}
|
|
398
|
+
if (trailingSlash && result !== "/" && result !== "." && !result.endsWith("/")) {
|
|
399
|
+
result += "/";
|
|
400
|
+
}
|
|
401
|
+
return result;
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* 判断路径是否为绝对路径
|
|
405
|
+
* @param path 路径
|
|
406
|
+
*/
|
|
407
|
+
static isAbsolute(path: string) {
|
|
408
|
+
return path.length > 0 && path.startsWith("/");
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* 获取文件名(可去除后缀)
|
|
412
|
+
* @param path 路径
|
|
413
|
+
* @param suffix 后缀(如扩展名)
|
|
414
|
+
*/
|
|
415
|
+
static basename(path: string, suffix?: string) {
|
|
416
|
+
if (path.length === 0) return "";
|
|
417
|
+
const normalized = Path.normalize(path);
|
|
418
|
+
if (normalized === "/") return "/";
|
|
419
|
+
let base = normalized.endsWith("/") ? normalized.slice(0, -1) : normalized;
|
|
420
|
+
base = base.slice(base.lastIndexOf("/") + 1);
|
|
421
|
+
if (suffix && base !== suffix && base.endsWith(suffix)) {
|
|
422
|
+
base = base.slice(0, base.length - suffix.length);
|
|
423
|
+
}
|
|
424
|
+
return base;
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* 获取文件所在目录
|
|
428
|
+
* @param path 路径
|
|
429
|
+
*/
|
|
430
|
+
static dirname(path: string) {
|
|
431
|
+
const normalized = Path.normalize(path);
|
|
432
|
+
if (normalized === "/" || normalized === ".") return normalized;
|
|
433
|
+
const parts = normalized.split("/");
|
|
434
|
+
parts.pop();
|
|
435
|
+
const result = parts.join("/");
|
|
436
|
+
if (result.length === 0) {
|
|
437
|
+
return Path.isAbsolute(normalized) ? "/" : ".";
|
|
438
|
+
}
|
|
439
|
+
return result;
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* 获取文件扩展名
|
|
443
|
+
* @param path 路径
|
|
444
|
+
*/
|
|
445
|
+
static extname(path: string) {
|
|
446
|
+
const base = Path.basename(path);
|
|
447
|
+
const lastDot = base.lastIndexOf(".");
|
|
448
|
+
if (lastDot <= 0) return "";
|
|
449
|
+
return base.slice(lastDot);
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* 解析路径
|
|
453
|
+
* @param path 路径
|
|
454
|
+
*/
|
|
455
|
+
static parse(path: string) {
|
|
456
|
+
const base = Path.basename(path);
|
|
457
|
+
const ext = Path.extname(base);
|
|
458
|
+
return {
|
|
459
|
+
root: Path.isAbsolute(path) ? "/" : "",
|
|
460
|
+
dir: Path.dirname(path),
|
|
461
|
+
base,
|
|
462
|
+
ext,
|
|
463
|
+
name: ext.length > 0 ? base.slice(0, base.length - ext.length) : base,
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* 计算从from到to的相对路径
|
|
468
|
+
* @param from 起始路径
|
|
469
|
+
* @param to 目标路径
|
|
470
|
+
*/
|
|
471
|
+
static relative(from: string, to: string) {
|
|
472
|
+
const fromParts = Path.resolve(from).split("/").filter((part) => part.length > 0);
|
|
473
|
+
const toParts = Path.resolve(to).split("/").filter((part) => part.length > 0);
|
|
474
|
+
let i = 0;
|
|
475
|
+
while (i < fromParts.length && i < toParts.length && fromParts[i] === toParts[i]) {
|
|
476
|
+
i++;
|
|
477
|
+
}
|
|
478
|
+
const up = new Array<string>(Math.max(0, fromParts.length - i)).fill("..").join("/");
|
|
479
|
+
const down = toParts.slice(i).join("/");
|
|
480
|
+
if (up.length > 0 && down.length > 0) return up + "/" + down;
|
|
481
|
+
if (up.length > 0) return up;
|
|
482
|
+
return down;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
|
|
277
486
|
const version = packageJson.version;
|
|
278
487
|
|
|
279
488
|
class VVVFS {
|
|
@@ -288,6 +497,10 @@ class VVVFS {
|
|
|
288
497
|
* 虚拟文件系统文件类
|
|
289
498
|
*/
|
|
290
499
|
static File = VVVFSFile;
|
|
500
|
+
/**
|
|
501
|
+
* path类(类似于NodeJS中的path模块)
|
|
502
|
+
*/
|
|
503
|
+
static path = Path;
|
|
291
504
|
/**
|
|
292
505
|
* 虚拟文件系统监听器
|
|
293
506
|
*/
|
package/package.json
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "vvvfs",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "一个使用IndexDB实现的虚拟文件系统",
|
|
5
|
-
"keywords": [
|
|
6
|
-
"Virtual",
|
|
7
|
-
"File",
|
|
8
|
-
"System",
|
|
9
|
-
"IFTC",
|
|
10
|
-
"VV",
|
|
11
|
-
"File",
|
|
12
|
-
"System",
|
|
13
|
-
"vfs",
|
|
14
|
-
"fs"
|
|
15
|
-
],
|
|
16
|
-
"license": "MIT",
|
|
17
|
-
"author": "IFTC",
|
|
18
|
-
"type": "module",
|
|
19
|
-
"main": "index.js",
|
|
20
|
-
"scripts": {
|
|
21
|
-
"test": "echo \"Error: no test specified\" && exit 1",
|
|
22
|
-
"build": "node esbuild.config.js"
|
|
23
|
-
},
|
|
24
|
-
"dependencies": {
|
|
25
|
-
"dexie": "^4.3.0",
|
|
26
|
-
"esbuild": "^0.27.3",
|
|
27
|
-
"mime": "^4.1.0"
|
|
28
|
-
},
|
|
29
|
-
"repository": {
|
|
30
|
-
"type": "git",
|
|
31
|
-
"url": "https://github.com/IFTC-XLKJ/vvvfs.git"
|
|
32
|
-
}
|
|
33
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "vvvfs",
|
|
3
|
+
"version": "0.1.6",
|
|
4
|
+
"description": "一个使用IndexDB实现的虚拟文件系统",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"Virtual",
|
|
7
|
+
"File",
|
|
8
|
+
"System",
|
|
9
|
+
"IFTC",
|
|
10
|
+
"VV",
|
|
11
|
+
"File",
|
|
12
|
+
"System",
|
|
13
|
+
"vfs",
|
|
14
|
+
"fs"
|
|
15
|
+
],
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"author": "IFTC",
|
|
18
|
+
"type": "module",
|
|
19
|
+
"main": "index.js",
|
|
20
|
+
"scripts": {
|
|
21
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
22
|
+
"build": "node esbuild.config.js"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"dexie": "^4.3.0",
|
|
26
|
+
"esbuild": "^0.27.3",
|
|
27
|
+
"mime": "^4.1.0"
|
|
28
|
+
},
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "https://github.com/IFTC-XLKJ/vvvfs.git"
|
|
32
|
+
}
|
|
33
|
+
}
|
package/types/index.d.ts
CHANGED
|
@@ -203,6 +203,110 @@ declare class VVVFSFile {
|
|
|
203
203
|
isLocked(): Promise<boolean>;
|
|
204
204
|
}
|
|
205
205
|
|
|
206
|
+
/**
|
|
207
|
+
* path类(类似于NodeJS中的path模块)
|
|
208
|
+
*/
|
|
209
|
+
declare class Path {
|
|
210
|
+
/**
|
|
211
|
+
* 路径分隔符
|
|
212
|
+
*/
|
|
213
|
+
static readonly sep: string;
|
|
214
|
+
/**
|
|
215
|
+
* 环境变量PATH的分隔符
|
|
216
|
+
*/
|
|
217
|
+
static readonly delimiter: string;
|
|
218
|
+
/**
|
|
219
|
+
* 构造函数
|
|
220
|
+
* @param paths 路径片段
|
|
221
|
+
*/
|
|
222
|
+
constructor(...paths: string[]);
|
|
223
|
+
/**
|
|
224
|
+
* 获取路径
|
|
225
|
+
*/
|
|
226
|
+
get path(): string;
|
|
227
|
+
/**
|
|
228
|
+
* 设置路径
|
|
229
|
+
* @param path 路径
|
|
230
|
+
*/
|
|
231
|
+
set path(path: string);
|
|
232
|
+
/**
|
|
233
|
+
* 获取文件名
|
|
234
|
+
*/
|
|
235
|
+
get name(): string;
|
|
236
|
+
/**
|
|
237
|
+
* 获取文件所在目录
|
|
238
|
+
*/
|
|
239
|
+
get parent(): string;
|
|
240
|
+
/**
|
|
241
|
+
* 获取文件扩展名
|
|
242
|
+
*/
|
|
243
|
+
get ext(): string;
|
|
244
|
+
/**
|
|
245
|
+
* 获取根目录("/"或"")
|
|
246
|
+
*/
|
|
247
|
+
get root(): string;
|
|
248
|
+
/**
|
|
249
|
+
* 判断路径是否为绝对路径
|
|
250
|
+
*/
|
|
251
|
+
isAbsolute(): boolean;
|
|
252
|
+
/**
|
|
253
|
+
* 合并路径
|
|
254
|
+
* @param paths 路径片段
|
|
255
|
+
*/
|
|
256
|
+
join(...paths: string[]): string;
|
|
257
|
+
/**
|
|
258
|
+
* 转换为字符串
|
|
259
|
+
*/
|
|
260
|
+
toString(): string;
|
|
261
|
+
/**
|
|
262
|
+
* 合并路径
|
|
263
|
+
* @param paths 路径片段
|
|
264
|
+
*/
|
|
265
|
+
static join(...paths: string[]): string;
|
|
266
|
+
/**
|
|
267
|
+
* 解析路径为绝对路径
|
|
268
|
+
* @param paths 路径片段
|
|
269
|
+
*/
|
|
270
|
+
static resolve(...paths: string[]): string;
|
|
271
|
+
/**
|
|
272
|
+
* 规范化路径(清除"."、解析"..")
|
|
273
|
+
* @param path 路径
|
|
274
|
+
*/
|
|
275
|
+
static normalize(path: string): string;
|
|
276
|
+
/**
|
|
277
|
+
* 判断路径是否为绝对路径
|
|
278
|
+
* @param path 路径
|
|
279
|
+
*/
|
|
280
|
+
static isAbsolute(path: string): boolean;
|
|
281
|
+
/**
|
|
282
|
+
* 获取文件名(可去除后缀)
|
|
283
|
+
* @param path 路径
|
|
284
|
+
* @param suffix 后缀(如扩展名)
|
|
285
|
+
*/
|
|
286
|
+
static basename(path: string, suffix?: string): string;
|
|
287
|
+
/**
|
|
288
|
+
* 获取文件所在目录
|
|
289
|
+
* @param path 路径
|
|
290
|
+
*/
|
|
291
|
+
static dirname(path: string): string;
|
|
292
|
+
/**
|
|
293
|
+
* 获取文件扩展名
|
|
294
|
+
* @param path 路径
|
|
295
|
+
*/
|
|
296
|
+
static extname(path: string): string;
|
|
297
|
+
/**
|
|
298
|
+
* 解析路径
|
|
299
|
+
* @param path 路径
|
|
300
|
+
*/
|
|
301
|
+
static parse(path: string): { root: string; dir: string; base: string; ext: string; name: string };
|
|
302
|
+
/**
|
|
303
|
+
* 计算从from到to的相对路径
|
|
304
|
+
* @param from 起始路径
|
|
305
|
+
* @param to 目标路径
|
|
306
|
+
*/
|
|
307
|
+
static relative(from: string, to: string): string;
|
|
308
|
+
}
|
|
309
|
+
|
|
206
310
|
/**
|
|
207
311
|
* 虚拟文件系统
|
|
208
312
|
* @author IFTC
|
|
@@ -222,6 +326,10 @@ declare class VVVFS {
|
|
|
222
326
|
* 虚拟文件系统文件类
|
|
223
327
|
*/
|
|
224
328
|
static File: typeof VVVFSFile;
|
|
329
|
+
/**
|
|
330
|
+
* path类(类似于NodeJS中的path模块)
|
|
331
|
+
*/
|
|
332
|
+
static path: typeof Path;
|
|
225
333
|
|
|
226
334
|
options: VVVFSOptions;
|
|
227
335
|
|