( filePath: string, data: string | NodeJS.ArrayBufferView, options?: WriteFileOptionsWithFlush, )
| 247 | * Sync file writes block the event loop and cause performance issues. |
| 248 | */ |
| 249 | export function writeFileSync_DEPRECATED( |
| 250 | filePath: string, |
| 251 | data: string | NodeJS.ArrayBufferView, |
| 252 | options?: WriteFileOptionsWithFlush, |
| 253 | ): void { |
| 254 | using _ = slowLogging`fs.writeFileSync(${filePath}, ${data})` |
| 255 | |
| 256 | // Check if flush is requested (for object-style options) |
| 257 | const needsFlush = |
| 258 | options !== null && |
| 259 | typeof options === 'object' && |
| 260 | 'flush' in options && |
| 261 | options.flush === true |
| 262 | |
| 263 | if (needsFlush) { |
| 264 | // Manual flush: open file, write, fsync, close |
| 265 | const encoding = |
| 266 | typeof options === 'object' && 'encoding' in options |
| 267 | ? options.encoding |
| 268 | : undefined |
| 269 | const mode = |
| 270 | typeof options === 'object' && 'mode' in options |
| 271 | ? options.mode |
| 272 | : undefined |
| 273 | let fd: number | undefined |
| 274 | try { |
| 275 | fd = openSync(filePath, 'w', mode) |
| 276 | fsWriteFileSync(fd, data, { encoding: encoding ?? undefined }) |
| 277 | fsyncSync(fd) |
| 278 | } finally { |
| 279 | if (fd !== undefined) { |
| 280 | closeSync(fd) |
| 281 | } |
| 282 | } |
| 283 | } else { |
| 284 | // No flush needed, use standard writeFileSync |
| 285 | fsWriteFileSync(filePath, data, options as WriteFileOptions) |
| 286 | } |
| 287 | } |
no outgoing calls
no test coverage detected