vvvfs 0.1.3 → 0.1.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 +9 -0
- package/index.html +1 -31
- package/index.js +34 -0
- package/index.ts +306 -686
- package/package.json +1 -1
- package/types/index.d.ts +396 -0
package/package.json
CHANGED
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
import { Dexie, Table } from "dexie";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 虚拟文件系统
|
|
5
|
+
*/
|
|
6
|
+
declare global {
|
|
7
|
+
// 扩展 Window 接口
|
|
8
|
+
interface window {
|
|
9
|
+
VVVFS: typeof VVVFS; // 如果 VVFS 是个类,这里可能需要调整,或者直接定义 vvfs 实例
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// 扩展 GlobalThis (针对你在 index.js 里的 globalThis.vvfs 写法)
|
|
13
|
+
// 注意:GlobalThis 和 Window 往往指向同一个对象,但在 TS 类型中有时需要分别处理
|
|
14
|
+
// var VVVFS: typeof VVVFS;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* 文件记录
|
|
20
|
+
* @param id 文件id
|
|
21
|
+
* @param name 文件名
|
|
22
|
+
* @param path 文件路径
|
|
23
|
+
* @param type 文件类型(file或dir)
|
|
24
|
+
* @param file 文件对象
|
|
25
|
+
* @param locked 是否锁定
|
|
26
|
+
*/
|
|
27
|
+
declare interface FileRecord {
|
|
28
|
+
id?: number;
|
|
29
|
+
name: string;
|
|
30
|
+
path: string;
|
|
31
|
+
type: string;
|
|
32
|
+
file: File | null;
|
|
33
|
+
locked?: boolean;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 虚拟文件系统数据库
|
|
38
|
+
* @param files 文件存储数据表
|
|
39
|
+
*/
|
|
40
|
+
declare interface VVVFSDatabase extends Dexie {
|
|
41
|
+
files: Table<FileRecord, number>;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* 虚拟文件系统配置项
|
|
46
|
+
* @param throwError 是否抛出错误
|
|
47
|
+
*/
|
|
48
|
+
declare interface VVVFSOptions {
|
|
49
|
+
throwError: boolean;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* 虚拟文件系统错误类
|
|
54
|
+
*/
|
|
55
|
+
declare class VVVFSError extends Error {
|
|
56
|
+
/**
|
|
57
|
+
* @param type 错误类型
|
|
58
|
+
* @param message 错误信息
|
|
59
|
+
*/
|
|
60
|
+
constructor(type: string, message: string);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* 虚拟文件系统文件类
|
|
65
|
+
* @param path 文件路径
|
|
66
|
+
*/
|
|
67
|
+
declare class VVVFSFile {
|
|
68
|
+
/**
|
|
69
|
+
* 获取文件路径
|
|
70
|
+
*/
|
|
71
|
+
get path(): string;
|
|
72
|
+
/**
|
|
73
|
+
* 设置文件路径
|
|
74
|
+
* @param path 文件路径
|
|
75
|
+
*/
|
|
76
|
+
set path(path: string);
|
|
77
|
+
/**
|
|
78
|
+
* 设置数据库名称
|
|
79
|
+
* @param dbname 数据库名称
|
|
80
|
+
*/
|
|
81
|
+
set dbname(dbname: string);
|
|
82
|
+
/**
|
|
83
|
+
* 获取数据库名称
|
|
84
|
+
*/
|
|
85
|
+
get dbname(): string;
|
|
86
|
+
set options(options: VVVFSOptions);
|
|
87
|
+
get options(): VVVFSOptions;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* 构造函数
|
|
91
|
+
* @param paths 文件路径
|
|
92
|
+
*/
|
|
93
|
+
constructor(...paths: string[]);
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* 读取文件
|
|
97
|
+
*/
|
|
98
|
+
read(): Promise<File | null>;
|
|
99
|
+
/**
|
|
100
|
+
* 读取文件文本内容
|
|
101
|
+
*/
|
|
102
|
+
readText(): Promise<string | null>;
|
|
103
|
+
/**
|
|
104
|
+
* 读取文件JSON内容
|
|
105
|
+
*/
|
|
106
|
+
readJSON(): Promise<Record<string, unknown> | null>;
|
|
107
|
+
/**
|
|
108
|
+
* 读取文件内容
|
|
109
|
+
* @param start 起始位置
|
|
110
|
+
* @param end 结束位置
|
|
111
|
+
*/
|
|
112
|
+
readChunk(start: number, end: number): Promise<Blob | null>;
|
|
113
|
+
/**
|
|
114
|
+
* 读取文件内容
|
|
115
|
+
* @param start 起始位置
|
|
116
|
+
* @param end 结束位置
|
|
117
|
+
*/
|
|
118
|
+
readTextChunk(start: number, end: number): Promise<string | null>;
|
|
119
|
+
/**
|
|
120
|
+
* 写入文件
|
|
121
|
+
* @param file 文件对象
|
|
122
|
+
*/
|
|
123
|
+
write(file: Blob): Promise<boolean>;
|
|
124
|
+
/**
|
|
125
|
+
* 写入文件文本内容
|
|
126
|
+
* @param text 文件文本内容
|
|
127
|
+
*/
|
|
128
|
+
writeText(text: string): Promise<boolean>;
|
|
129
|
+
/**
|
|
130
|
+
* 写入文件JSON内容
|
|
131
|
+
* @param json 文件JSON内容
|
|
132
|
+
*/
|
|
133
|
+
writeJSON(json: Record<string, unknown>, format?: boolean): Promise<boolean>;
|
|
134
|
+
/**
|
|
135
|
+
* 追加文件内容
|
|
136
|
+
* @param file 文件对象
|
|
137
|
+
*/
|
|
138
|
+
append(file: Blob): Promise<boolean>;
|
|
139
|
+
/**
|
|
140
|
+
* 追加文件文本内容
|
|
141
|
+
* @param text 文件文本内容
|
|
142
|
+
*/
|
|
143
|
+
appendText(text: string): Promise<boolean>;
|
|
144
|
+
/**
|
|
145
|
+
* 创建文件
|
|
146
|
+
*/
|
|
147
|
+
createFile(): Promise<boolean>;
|
|
148
|
+
/**
|
|
149
|
+
* 创建文件夹
|
|
150
|
+
*/
|
|
151
|
+
createDir(): Promise<boolean>;
|
|
152
|
+
/**
|
|
153
|
+
* 删除文件
|
|
154
|
+
*/
|
|
155
|
+
delete(): Promise<boolean>;
|
|
156
|
+
/**
|
|
157
|
+
* 判断文件是否存在
|
|
158
|
+
*/
|
|
159
|
+
exists(): Promise<boolean>;
|
|
160
|
+
/**
|
|
161
|
+
* 获取文件大小
|
|
162
|
+
*/
|
|
163
|
+
isFile(): Promise<boolean>;
|
|
164
|
+
/**
|
|
165
|
+
* 判断文件是否是文件夹
|
|
166
|
+
*/
|
|
167
|
+
isDir(): Promise<boolean>;
|
|
168
|
+
/**
|
|
169
|
+
* 列出文件
|
|
170
|
+
*/
|
|
171
|
+
list(): Promise<string[]>;
|
|
172
|
+
/**
|
|
173
|
+
* 重命名文件
|
|
174
|
+
*/
|
|
175
|
+
rename(newName: string): Promise<boolean>;
|
|
176
|
+
/**
|
|
177
|
+
* 移动文件
|
|
178
|
+
*/
|
|
179
|
+
move(newPath: string): Promise<boolean>;
|
|
180
|
+
/**
|
|
181
|
+
* 复制文件
|
|
182
|
+
*/
|
|
183
|
+
copy(newPath: string): Promise<boolean>;
|
|
184
|
+
/**
|
|
185
|
+
* 搜索文件
|
|
186
|
+
*/
|
|
187
|
+
search(query: string): Promise<string[] | null>;
|
|
188
|
+
/**
|
|
189
|
+
* 监听文件
|
|
190
|
+
*/
|
|
191
|
+
watch(handler: (type: string) => Promise<boolean>): void;
|
|
192
|
+
/**
|
|
193
|
+
* 锁定文件
|
|
194
|
+
*/
|
|
195
|
+
lock(): Promise<boolean>;
|
|
196
|
+
/**
|
|
197
|
+
* 解锁文件
|
|
198
|
+
*/
|
|
199
|
+
unlock(): Promise<boolean>;
|
|
200
|
+
/**
|
|
201
|
+
* 判断文件是否已锁定
|
|
202
|
+
*/
|
|
203
|
+
isLocked(): Promise<boolean>;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* 虚拟文件系统
|
|
208
|
+
* @author IFTC
|
|
209
|
+
* @description 虚拟文件系统
|
|
210
|
+
*/
|
|
211
|
+
declare class VVVFS {
|
|
212
|
+
static defaultDBName: string;
|
|
213
|
+
/**
|
|
214
|
+
* 虚拟文件系统版本
|
|
215
|
+
*/
|
|
216
|
+
static readonly version: string;
|
|
217
|
+
/**
|
|
218
|
+
* 虚拟文件系统作者
|
|
219
|
+
*/
|
|
220
|
+
static readonly author: string;
|
|
221
|
+
/**
|
|
222
|
+
* 虚拟文件系统文件类
|
|
223
|
+
*/
|
|
224
|
+
static File: typeof VVVFSFile;
|
|
225
|
+
|
|
226
|
+
options: VVVFSOptions;
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* 创建虚拟文件系统
|
|
230
|
+
* @param name 虚拟文件系统名称
|
|
231
|
+
* @param options 配置项
|
|
232
|
+
*/
|
|
233
|
+
constructor(name?: string, options?: VVVFSOptions);
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* 初始化虚拟文件系统
|
|
237
|
+
* @description 将Linux的系统初始文件初始化到数据库中
|
|
238
|
+
*/
|
|
239
|
+
init(user?: string): Promise<void>;
|
|
240
|
+
/**
|
|
241
|
+
* 重置虚拟文件系统
|
|
242
|
+
*/
|
|
243
|
+
reset(): Promise<void>;
|
|
244
|
+
/**
|
|
245
|
+
* 创建文件
|
|
246
|
+
* @param path 文件路径
|
|
247
|
+
*/
|
|
248
|
+
createFile(path: string): Promise<boolean>;
|
|
249
|
+
/**
|
|
250
|
+
* 创建目录
|
|
251
|
+
* @param path 目录路径
|
|
252
|
+
*/
|
|
253
|
+
createDir(path: string): Promise<boolean>;
|
|
254
|
+
/**
|
|
255
|
+
* 判断文件是否存在
|
|
256
|
+
* @param path 文件路径
|
|
257
|
+
*/
|
|
258
|
+
exists(path: string): Promise<boolean>;
|
|
259
|
+
/**
|
|
260
|
+
* 读取文件内容
|
|
261
|
+
* @param path 文件路径
|
|
262
|
+
*/
|
|
263
|
+
read(path: string): Promise<File | null>;
|
|
264
|
+
/**
|
|
265
|
+
* 读取文件文本内容
|
|
266
|
+
* @param path 文件路径
|
|
267
|
+
*/
|
|
268
|
+
readText(path: string): Promise<string | null>;
|
|
269
|
+
/**
|
|
270
|
+
* 读取JSON内容
|
|
271
|
+
* @param path 文件路径
|
|
272
|
+
*/
|
|
273
|
+
readJson(path: string): Promise<Record<string, unknown> | null>;
|
|
274
|
+
/**
|
|
275
|
+
* 写入文件
|
|
276
|
+
* @param path 文件路径
|
|
277
|
+
* @param content 文件内容
|
|
278
|
+
*/
|
|
279
|
+
write(path: string, content: Blob): Promise<boolean>;
|
|
280
|
+
/**
|
|
281
|
+
* 写入文本内容
|
|
282
|
+
* @param path 文件路径
|
|
283
|
+
* @param content 文本内容
|
|
284
|
+
*/
|
|
285
|
+
writeText(path: string, content: string): Promise<boolean>;
|
|
286
|
+
/**
|
|
287
|
+
* 写入JSON内容
|
|
288
|
+
* @param path 文件路径
|
|
289
|
+
* @param content JSON内容
|
|
290
|
+
* @param format 是否格式化
|
|
291
|
+
*/
|
|
292
|
+
writeJson(path: string, content: Record<string, unknown>, format?: boolean): Promise<boolean>;
|
|
293
|
+
/**
|
|
294
|
+
* 追加内容
|
|
295
|
+
* @param path 文件路径
|
|
296
|
+
* @param content 追加内容
|
|
297
|
+
*/
|
|
298
|
+
append(path: string, content: Blob): Promise<boolean>;
|
|
299
|
+
/**
|
|
300
|
+
* 追加文本内容
|
|
301
|
+
* @param path 文件路径
|
|
302
|
+
* @param content 追加内容
|
|
303
|
+
*/
|
|
304
|
+
appendText(path: string, content: string): Promise<boolean>;
|
|
305
|
+
/**
|
|
306
|
+
* 读取文件内容
|
|
307
|
+
* @param path 文件路径
|
|
308
|
+
* @param start 开始位置
|
|
309
|
+
* @param end 结束位置
|
|
310
|
+
*/
|
|
311
|
+
readChunk(path: string, start: number, end: number): Promise<Blob | null>;
|
|
312
|
+
/**
|
|
313
|
+
* 读取文件内容
|
|
314
|
+
* @param path 文件路径
|
|
315
|
+
* @param start 读取开始位置
|
|
316
|
+
* @param end 读取结束位置
|
|
317
|
+
*/
|
|
318
|
+
readTextChunk(path: string, start: number, end: number): Promise<string | null>;
|
|
319
|
+
/**
|
|
320
|
+
* 判断是否是文件
|
|
321
|
+
* @param path 文件路径
|
|
322
|
+
*/
|
|
323
|
+
isFile(path: string): Promise<boolean>;
|
|
324
|
+
/**
|
|
325
|
+
* 判断是否是目录
|
|
326
|
+
* @param path 文件路径
|
|
327
|
+
*/
|
|
328
|
+
isDir(path: string): Promise<boolean>;
|
|
329
|
+
/**
|
|
330
|
+
* 列出目录下的文件
|
|
331
|
+
* @param path 目录路径
|
|
332
|
+
*/
|
|
333
|
+
list(path: string): Promise<string[]>;
|
|
334
|
+
/**
|
|
335
|
+
* 重命名文件
|
|
336
|
+
* @param path 文件路径
|
|
337
|
+
* @param newName 新文件名
|
|
338
|
+
*/
|
|
339
|
+
rename(path: string, newName: string): Promise<boolean>;
|
|
340
|
+
/**
|
|
341
|
+
* 删除文件
|
|
342
|
+
* @param path 文件路径
|
|
343
|
+
*/
|
|
344
|
+
delete(path: string): Promise<boolean>;
|
|
345
|
+
/**
|
|
346
|
+
* 移动文件
|
|
347
|
+
* @param path 文件路径
|
|
348
|
+
* @param newPath 新路径
|
|
349
|
+
*/
|
|
350
|
+
move(path: string, newPath: string): Promise<boolean>;
|
|
351
|
+
/**
|
|
352
|
+
* 复制文件
|
|
353
|
+
* @param path 文件路径
|
|
354
|
+
* @param newPath 新路径
|
|
355
|
+
*/
|
|
356
|
+
copy(path: string, newPath: string): Promise<boolean>;
|
|
357
|
+
/**
|
|
358
|
+
* 搜索文件
|
|
359
|
+
* @param basePath 基础路径
|
|
360
|
+
* @param query 查询字符串
|
|
361
|
+
*/
|
|
362
|
+
search(basePath: string, query: string): Promise<string[] | null>;
|
|
363
|
+
/**
|
|
364
|
+
* 监听文件
|
|
365
|
+
* @param path 文件路径
|
|
366
|
+
* @param handler 监听器
|
|
367
|
+
*/
|
|
368
|
+
watch(path: string, handler: (type: string) => Promise<boolean>): void;
|
|
369
|
+
/**
|
|
370
|
+
* 锁定文件
|
|
371
|
+
* @param path 文件路径
|
|
372
|
+
*/
|
|
373
|
+
lock(path: string): Promise<boolean>;
|
|
374
|
+
/**
|
|
375
|
+
* 解锁文件
|
|
376
|
+
* @param path 文件路径
|
|
377
|
+
*/
|
|
378
|
+
unlock(path: string): Promise<boolean>;
|
|
379
|
+
/**
|
|
380
|
+
* 判断文件是否已锁定
|
|
381
|
+
* @param path 文件路径
|
|
382
|
+
*/
|
|
383
|
+
isLocked(path: string): Promise<boolean>;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* 解析路径
|
|
388
|
+
* @param path 路径
|
|
389
|
+
*/
|
|
390
|
+
declare function parsePath(path: string): { name: string; parent: string };
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* 合并路径
|
|
394
|
+
* @param paths 路径
|
|
395
|
+
*/
|
|
396
|
+
declare function joinPath(...paths: string[]): string;
|