( path: string | URL, data: Uint8Array, options?: WriteFileOptions, )
| 82 | * @param options Options to write files. See {@linkcode WriteFileOptions}. |
| 83 | */ |
| 84 | export function writeFileSync( |
| 85 | path: string | URL, |
| 86 | data: Uint8Array, |
| 87 | options?: WriteFileOptions, |
| 88 | ): void { |
| 89 | if (isDeno) { |
| 90 | Deno.writeFileSync(path, data, { ...options }); |
| 91 | } else { |
| 92 | const { |
| 93 | append = false, |
| 94 | create = true, |
| 95 | createNew = false, |
| 96 | mode, |
| 97 | signal, |
| 98 | } = options ?? {}; |
| 99 | |
| 100 | const flag = getWriteFsFlag({ append, create, createNew }); |
| 101 | try { |
| 102 | getNodeFs().writeFileSync(path, data, { flag, signal }); |
| 103 | if (mode != null) { |
| 104 | getNodeFs().chmodSync(path, mode); |
| 105 | } |
| 106 | } catch (error) { |
| 107 | throw mapError(error); |
| 108 | } |
| 109 | } |
| 110 | } |
no test coverage detected