| 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; |
| 692 | // Get file. |
| 693 | this.open(fname, flag, 0x1a4, function(err: ApiError, fd?: File) { |
| 694 | if (err) { |
| 695 | return cb(err); |
| 696 | } |
| 697 | cb = function(err: ApiError) { |
| 698 | fd!.close(function(err2: any) { |
| 699 | oldCb(err ? err : err2); |
| 700 | }); |
| 701 | }; |
| 702 | |
| 703 | try { |
| 704 | if (typeof data === 'string') { |
| 705 | data = Buffer.from(data, encoding!); |
| 706 | } |
| 707 | } catch (e) { |
| 708 | return cb(e); |
| 709 | } |
| 710 | // Write into file. |
| 711 | fd!.write(data, 0, data.length, 0, cb); |
| 712 | }); |
| 713 | } |
| 714 | public writeFileSync(fname: string, data: any, encoding: string | null, flag: FileFlag, mode: number): void { |
| 715 | // Get file. |
| 716 | const fd = this.openSync(fname, flag, mode); |