( path: string | URL, options?: OpenOptions, )
| 101 | * @returns A Promise that resolves to a {@linkcode FsFile} instance. |
| 102 | */ |
| 103 | export async function open( |
| 104 | path: string | URL, |
| 105 | options?: OpenOptions, |
| 106 | ): Promise<FsFile> { |
| 107 | if (isDeno) { |
| 108 | return Deno.open(path, options); |
| 109 | } else { |
| 110 | const { |
| 111 | read = true, |
| 112 | write = false, |
| 113 | append = false, |
| 114 | truncate = false, |
| 115 | create = false, |
| 116 | createNew = false, |
| 117 | mode = 0o666, |
| 118 | } = options ?? {}; |
| 119 | |
| 120 | try { |
| 121 | const flag = getOpenFsFlag({ |
| 122 | read, |
| 123 | write, |
| 124 | append, |
| 125 | truncate, |
| 126 | create, |
| 127 | createNew, |
| 128 | }); |
| 129 | const { open } = getNodeFs(); |
| 130 | const { promisify } = getNodeUtil(); |
| 131 | const nodeOpenFd = promisify(open); |
| 132 | |
| 133 | const fd = await nodeOpenFd(path, flag, mode); |
| 134 | return new NodeFsFile(fd) as FsFile; |
| 135 | } catch (error) { |
| 136 | throw mapError(error); |
| 137 | } |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * Synchronously open a file and return an instance of {@linkcode FsFile}. |
no test coverage detected