MCPcopy
hub / github.com/jvilk/BrowserFS / readFileSync

Method readFileSync

src/core/file_system.ts:672–688  ·  view source on GitHub ↗
(fname: string, encoding: string | null, flag: FileFlag)

Source from the content-addressed store, hash-verified

670 });
671 }
672 public readFileSync(fname: string, encoding: string | null, flag: FileFlag): any {
673 // Get file.
674 const fd = this.openSync(fname, flag, 0x1a4);
675 try {
676 const stat = fd.statSync();
677 // Allocate buffer.
678 const buf = Buffer.alloc(stat.size);
679 fd.readSync(buf, 0, stat.size, 0);
680 fd.closeSync();
681 if (encoding === null) {
682 return buf;
683 }
684 return buf.toString(encoding);
685 } finally {
686 fd.closeSync();
687 }
688 }
689 public writeFile(fname: string, data: any, encoding: string | null, flag: FileFlag, mode: number, cb: BFSOneArgCallback): void {
690 // Wrap cb in file closing code.
691 const oldCb = cb;

Callers

nothing calls this directly

Calls 5

openSyncMethod · 0.95
toStringMethod · 0.80
statSyncMethod · 0.65
readSyncMethod · 0.65
closeSyncMethod · 0.65

Tested by

no test coverage detected