* Asynchronously appends data to a file. * @param {string | Buffer | URL | number} path * @param {string | Buffer} data * @param {{ * encoding?: string | null; * mode?: number; * flag?: string; * flush?: boolean; * } | string} [options] * @param {(err?: Error) => any} callback *
(path, data, options, callback)
| 2958 | * @returns {void} |
| 2959 | */ |
| 2960 | function appendFile(path, data, options, callback) { |
| 2961 | callback ||= options; |
| 2962 | validateFunction(callback, 'cb'); |
| 2963 | |
| 2964 | options = getOptions(typeof options === 'function' ? null : options, { |
| 2965 | encoding: 'utf8', mode: 0o666, flag: 'a', |
| 2966 | }); |
| 2967 | parseFileMode(options.mode, 'mode', 0o666); |
| 2968 | |
| 2969 | const h = vfsState.handlers; |
| 2970 | if (h !== null) { |
| 2971 | if (checkAborted(options.signal, callback)) return; |
| 2972 | if (vfsVoid(h.appendFile(path, data, options), callback)) return; |
| 2973 | } |
| 2974 | |
| 2975 | // Don't make changes directly on options object |
| 2976 | options = copyObject(options); |
| 2977 | |
| 2978 | // Force append behavior when using a supplied file descriptor |
| 2979 | if (!options.flag || isFd(path)) |
| 2980 | options.flag = 'a'; |
| 2981 | |
| 2982 | fs.writeFile(path, data, options, callback); |
| 2983 | } |
| 2984 | |
| 2985 | /** |
| 2986 | * Synchronously appends data to a file. |
nothing calls this directly
no test coverage detected
searching dependent graphs…