( path: string | URL, data: Uint8Array | ReadableStream<Uint8Array>, options?: WriteFileOptions, )
| 30 | * @param options Options to write files. See {@linkcode WriteFileOptions}. |
| 31 | */ |
| 32 | export async function writeFile( |
| 33 | path: string | URL, |
| 34 | data: Uint8Array | ReadableStream<Uint8Array>, |
| 35 | options?: WriteFileOptions, |
| 36 | ): Promise<void> { |
| 37 | if (isDeno) { |
| 38 | await Deno.writeFile(path, data, { ...options }); |
| 39 | } else { |
| 40 | const { |
| 41 | append = false, |
| 42 | create = true, |
| 43 | createNew = false, |
| 44 | mode, |
| 45 | signal, |
| 46 | } = options ?? {}; |
| 47 | |
| 48 | const flag = getWriteFsFlag({ append, create, createNew }); |
| 49 | try { |
| 50 | await getNodeFs().promises.writeFile(path, data, { flag, signal }); |
| 51 | if (mode != null) { |
| 52 | await getNodeFs().promises.chmod(path, mode); |
| 53 | } |
| 54 | } catch (error) { |
| 55 | throw mapError(error); |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Synchronously write `data` to the given `path`, by default creating a new |
no test coverage detected