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