| 887 | } |
| 888 | |
| 889 | public openFile(p: string, flag: FileFlag, cb: BFSCallback<File>): void { |
| 890 | const tx = this.store.beginTransaction('readonly'); |
| 891 | // Step 1: Grab the file's inode. |
| 892 | this.findINode(tx, p, (e: ApiError, inode?: Inode) => { |
| 893 | if (noError(e, cb)) { |
| 894 | // Step 2: Grab the file's data. |
| 895 | tx.get(inode!.id, (e: ApiError, data?: Buffer): void => { |
| 896 | if (noError(e, cb)) { |
| 897 | if (data === undefined) { |
| 898 | cb(ApiError.ENOENT(p)); |
| 899 | } else { |
| 900 | cb(null, new AsyncKeyValueFile(this, p, flag, inode!.toStats(), data)); |
| 901 | } |
| 902 | } |
| 903 | }); |
| 904 | } |
| 905 | }); |
| 906 | } |
| 907 | |
| 908 | public unlink(p: string, cb: BFSOneArgCallback): void { |
| 909 | this.removeEntry(p, false, cb); |