MCPcopy Index your code
hub / github.com/browserless/browserless / read

Method read

src/file-system.ts:96–117  ·  view source on GitHub ↗

* Reads contents from the local map, if any exist and the file hasn't * changed on disk since hydration, or loads from the file system and * hydrates the cache for the particular filepath * * @param path The filepath of the contents to read * @returns Promise of the contents separated

(path: string, encoded: boolean)

Source from the content-addressed store, hash-verified

94 * @returns Promise of the contents separated by newlines
95 */
96 public async read(path: string, encoded: boolean): Promise<string[]> {
97 const mtime = await this.getMtime(path);
98
99 if (this.fsMap.has(path) && this.mtimes.get(path) === mtime) {
100 return this.fsMap.get(path) as string[];
101 }
102 const contents = (await readFile(path).catch(() => '')).toString();
103 const decoded =
104 encoded && contents.length
105 ? await decrypt(contents, this.currentAESKey)
106 : contents;
107 const splitContents = decoded.length ? decoded.split('\n') : [];
108
109 this.fsMap.set(path, splitContents);
110 if (mtime !== null) {
111 this.mtimes.set(path, mtime);
112 } else {
113 this.mtimes.delete(path);
114 }
115
116 return splitContents;
117 }
118
119 protected async getMtime(path: string): Promise<number | null> {
120 return stat(path).then(

Callers 1

appendMethod · 0.95

Calls 4

getMtimeMethod · 0.95
readFileFunction · 0.85
decryptFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected