MCPcopy Index your code
hub / github.com/angular/angular / NodeFilesystem

Class NodeFilesystem

packages/service-worker/cli/filesystem.ts:15–56  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13import {sha1Binary} from './sha1';
14
15export class NodeFilesystem implements Filesystem {
16 constructor(private base: string) {}
17
18 async list(_path: string): Promise<string[]> {
19 const dir = this.canonical(_path);
20 const entries = fs
21 .readdirSync(dir)
22 .map((entry: string) => ({entry, stats: fs.statSync(path.join(dir, entry))}));
23 const files = entries
24 .filter((entry: any) => !entry.stats.isDirectory())
25 .map((entry: any) => path.posix.join(_path, entry.entry));
26
27 return entries
28 .filter((entry: any) => entry.stats.isDirectory())
29 .map((entry: any) => path.posix.join(_path, entry.entry))
30 .reduce(
31 async (list: Promise<string[]>, subdir: string) =>
32 (await list).concat(await this.list(subdir)),
33 Promise.resolve(files),
34 );
35 }
36
37 async read(_path: string): Promise<string> {
38 const file = this.canonical(_path);
39 return fs.readFileSync(file).toString();
40 }
41
42 async hash(_path: string): Promise<string> {
43 const file = this.canonical(_path);
44 const contents: Buffer = fs.readFileSync(file);
45 return sha1Binary(contents as any as ArrayBuffer);
46 }
47
48 async write(_path: string, contents: string): Promise<void> {
49 const file = this.canonical(_path);
50 fs.writeFileSync(file, contents);
51 }
52
53 private canonical(_path: string): string {
54 return path.posix.join(this.base, _path);
55 }
56}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…