{"id":17472656,"url":"https://github.com/shinnn/write-file-atomically","last_synced_at":"2025-04-09T22:54:22.482Z","repository":{"id":57399819,"uuid":"52953452","full_name":"shinnn/write-file-atomically","owner":"shinnn","description":"Promisified version of write-file-atomic","archived":false,"fork":false,"pushed_at":"2018-02-26T06:43:03.000Z","size":118,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-09T22:54:16.369Z","etag":null,"topics":["async","atomic-operation","file-system","graceful","javascript","nodejs","promise","promisified","write"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shinnn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-03-02T10:12:25.000Z","updated_at":"2018-02-15T03:43:41.000Z","dependencies_parsed_at":"2022-09-26T17:01:17.995Z","dependency_job_id":null,"html_url":"https://github.com/shinnn/write-file-atomically","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shinnn%2Fwrite-file-atomically","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shinnn%2Fwrite-file-atomically/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shinnn%2Fwrite-file-atomically/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shinnn%2Fwrite-file-atomically/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shinnn","download_url":"https://codeload.github.com/shinnn/write-file-atomically/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248125632,"owners_count":21051766,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["async","atomic-operation","file-system","graceful","javascript","nodejs","promise","promisified","write"],"created_at":"2024-10-18T17:30:22.978Z","updated_at":"2025-04-09T22:54:22.458Z","avatar_url":"https://github.com/shinnn.png","language":"JavaScript","readme":"# write-file-atomically\n\n[![npm version](https://img.shields.io/npm/v/write-file-atomically.svg)](https://www.npmjs.com/package/write-file-atomically)\n[![Build Status](https://travis-ci.org/shinnn/write-file-atomically.svg?branch=master)](https://travis-ci.org/shinnn/write-file-atomically)\n[![Coverage Status](https://img.shields.io/coveralls/shinnn/write-file-atomically.svg)](https://coveralls.io/github/shinnn/write-file-atomically?branch=master)\n\n[Promisified](https://promise-nuggets.github.io/articles/07-wrapping-callback-functions.html) version of [write-file-atomic](https://github.com/npm/write-file-atomic):\n\n\u003e an extension for node's `fs.writeFile` that makes its operation atomic and allows you set ownership (uid/gid of the file)\n\n```javascript\nconst {readFileSync} = require('fs');\nconst writeFileAtomically = require('write-file-atomically');\n\n(async () =\u003e {\n  await writeFileAtomically('file.txt', 'Hi!');\n  readFileSync('file.txt', 'utf8'); //=\u003e 'Hi!'\n})();\n```\n\n## Installation\n\n[Use](https://docs.npmjs.com/cli/install) [npm](https://docs.npmjs.com/getting-started/what-is-npm).\n\n```\nnpm install write-file-atomically\n```\n\n## API\n\n```javascript\nconst writeFileAtomically = require('write-file-atomically');\n```\n\n### writeFileAtomically(*filename*, *data* [, *options*])\n\n*filename*: `string`, `Buffer` or [`URL`](https://nodejs.org/api/url.html#url_class_url) (a file path where the file to be written)  \n*data*: `string` or `Buffer` (file contents)  \n*options*: `Object` or `string` (directly used as [`write-file-atomic` options](https://github.com/npm/write-file-atomic#var-writefileatomic--requirewrite-file-atomicwritefileatomicfilename-data-options-callback))  \nReturn: `Promise`\n\nIt asynchronously writes data to the given file path in an [atomic manner](https://www.npmjs.com/package/write-file-atomic#var-writefileatomic--requirewrite-file-atomic-writefileatomicfilename-data-options-callback):\n\n\u003e The file is initially named `filename + \".\" + murmurhex(__filename, process.pid, ++invocations)`. If writeFile completes successfully then, if passed the **chown** option it will change the ownership of the file. Finally it renames the file back to the filename you specified.\n\n## License\n\n[ISC License](./LICENSE) © 2018 Shinnosuke Watanabe\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshinnn%2Fwrite-file-atomically","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshinnn%2Fwrite-file-atomically","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshinnn%2Fwrite-file-atomically/lists"}