How to use the memfs/lib/volume.filenameToSteps function in memfs

To help you get started, we’ve selected a few memfs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wasmerio / wasmer-js / packages / wasmfs / src / index.ts View on Github external
fromJSONFixed(vol: Volume, json: DirectoryJSON) {
    const sep = "/";
    for (let filename in json) {
      const data = json[filename];
      const isDir = data ? Object.getPrototypeOf(data) === null : data === null;
      // const isDir = typeof data === "string" || ((data as any) instanceof Buffer && data !== null);
      if (!isDir) {
        const steps = filenameToSteps(filename);
        if (steps.length > 1) {
          const dirname = sep + steps.slice(0, steps.length - 1).join(sep);
          // @ts-ignore
          vol.mkdirpBase(dirname, 0o777);
        }
        vol.writeFileSync(filename, (data as any) || "");
      } else {
        // @ts-ignore
        vol.mkdirpBase(filename, 0o777);
      }
    }
  }