| 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; |