Download next.js/packages/next/src/lib/fs/write-atomic.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 457 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/packages/next/src/lib/fs/write-atomic.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/next.js/packages/next/src/lib/fs/write-atomic.ts
-
curl -L -o write-atomic.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/packages/next/src/lib/fs/write-atomic.ts
457 Bytes
| import { unlink, writeFile } from 'fs/promises' | |
| import { rename } from './rename' | |
| export async function writeFileAtomic( | |
| filePath: string, | |
| content: string | |
| ): Promise<void> { | |
| const tempPath = filePath + '.tmp.' + Math.random().toString(36).slice(2) | |
| try { | |
| await writeFile(tempPath, content, 'utf-8') | |
| await rename(tempPath, filePath) | |
| } catch (e) { | |
| try { | |
| await unlink(tempPath) | |
| } catch { | |
| // ignore | |
| } | |
| throw e | |
| } | |
| } | |