vvvfs 0.2.4 → 0.2.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/index.ts CHANGED
@@ -603,6 +603,15 @@ class VVVFS {
603
603
  static defaultDBName = "vvvfs";
604
604
  #db: VVVFSDatabase;
605
605
  options: VVVFSOptions;
606
+ /**
607
+ * 主文件表(Master File Table)
608
+ * @description 只读属性,返回文件系统中所有文件/目录的记录,类似 NTFS 的主文件表(MFT)
609
+ */
610
+ get MFT(): Promise<FileRecord[]> {
611
+ return this.#withErrorHandling("MFT", async () => {
612
+ return await this.#db.files.toArray();
613
+ }, [] as FileRecord[]);
614
+ }
606
615
  /**
607
616
  * 虚拟文件系统版本
608
617
  */
@@ -739,7 +748,7 @@ class VVVFS {
739
748
  "lib", "lib64", "media", "mnt", "opt", "proc",
740
749
  "run", "sbin", "srv", "sys", "tmp", "usr", "var",
741
750
  ];
742
- const linuxInitFiles = linuxDirs.map((name) => ({
751
+ const linuxInitFiles: FileRecord[] = linuxDirs.map((name) => ({
743
752
  name,
744
753
  path: "/",
745
754
  type: "dir" as const,
@@ -1754,49 +1763,48 @@ class VVVFS {
1754
1763
  /**
1755
1764
  * 解析路径
1756
1765
  * @param path 路径
1766
+ * @returns name 文件名、parent 父目录路径
1767
+ * @throws 文件名或路径过长时抛出 VVVFSError
1757
1768
  */
1758
1769
  function parsePath(path: string) {
1759
- path = joinPath(path);
1760
- const oldParts = path.split("/");
1770
+ const normalized = joinPath(path);
1761
1771
  const parts: string[] = [];
1762
- for (let i = 0; i < oldParts.length; i++) {
1763
- if (oldParts[i].length > 255) throw new VVVFSError("ParsePath", "文件名过长");
1764
- if (oldParts[i]) parts.push(oldParts[i]);
1772
+ for (const part of normalized.split("/")) {
1773
+ if (!part) continue;
1774
+ if (part.length > 255) throw new VVVFSError("ParsePath", "文件名过长");
1775
+ parts.push(part);
1765
1776
  }
1766
1777
  const name = parts.pop() || "";
1767
- const parent = "/" + parts.join("/");
1768
- if (joinPath(parent, name).length > 4096) throw new VVVFSError("ParsePath", "文件路径过长");
1778
+ const parent = parts.length > 0 ? "/" + parts.join("/") : "/";
1779
+ if (parent.length + 1 + name.length > 4096) {
1780
+ throw new VVVFSError("ParsePath", "文件路径过长");
1781
+ }
1769
1782
  return { name, parent };
1770
1783
  }
1771
1784
 
1772
1785
  /**
1773
- * 合并路径
1774
- * @param paths 路径
1786
+ * 合并路径(始终返回以 / 开头的绝对路径)
1787
+ * @param paths 路径片段
1775
1788
  */
1776
- function joinPath(...paths: string[]) {
1777
- const segments = paths.map((p) => String(p)).filter((p) => p.length > 0);
1778
- if (segments.length === 0) return ".";
1779
- const isAbsolute = segments[0].startsWith("/");
1780
- const parts = segments.join("/").split("/");
1789
+ function joinPath(...paths: string[]): string {
1790
+ const joined = paths.filter((p) => p !== "").join("/");
1791
+ if (joined === "") return "/";
1792
+ const isAbsolute = joined.startsWith("/");
1781
1793
  const stack: string[] = [];
1782
- for (const part of parts) {
1783
- if (part === "" || part === ".") {
1784
- continue;
1785
- } else if (part === "..") {
1794
+ for (const part of joined.split("/")) {
1795
+ if (part === "" || part === ".") continue;
1796
+ if (part === "..") {
1786
1797
  if (stack.length > 0 && stack[stack.length - 1] !== "..") {
1787
1798
  stack.pop();
1788
1799
  } else if (!isAbsolute) {
1789
1800
  stack.push("..");
1790
1801
  }
1791
- } else {
1792
- stack.push(part);
1802
+ continue;
1793
1803
  }
1804
+ stack.push(part);
1794
1805
  }
1795
- let result = stack.join("/");
1796
- if (isAbsolute) {
1797
- result = "/" + result;
1798
- }
1799
- return result.startsWith("/") ? result : "/" + result || (isAbsolute ? "/" : ".");
1806
+ const result = (isAbsolute ? "/" : "") + stack.join("/");
1807
+ return result || (isAbsolute ? "/" : ".");
1800
1808
  }
1801
1809
  Object.defineProperty(VVVFS, "version", {
1802
1810
  value: version,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vvvfs",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "description": "一个使用IndexDB实现的虚拟文件系统",
5
5
  "keywords": [
6
6
  "Virtual",
package/types/index.d.ts CHANGED
@@ -418,6 +418,12 @@ export class VVVFS {
418
418
 
419
419
  options: VVVFSOptions;
420
420
 
421
+ /**
422
+ * 主文件表(Master File Table)
423
+ * @description 只读属性,返回文件系统中所有文件/目录的记录,类似 NTFS 的主文件表(MFT)
424
+ */
425
+ get MFT(): Promise<FileRecord[]>;
426
+
421
427
  /**
422
428
  * 创建虚拟文件系统
423
429
  * @param name 虚拟文件系统名称