{"_id":"safe-replace","_rev":"10-be05c6e1312a56c6db59501fbf9a2d19","name":"safe-replace","description":"A micro-module for safely replacing a file.","dist-tags":{"latest":"1.1.0"},"versions":{"1.0.0":{"name":"safe-replace","version":"1.0.0","description":"A micro-module for safely replacing a file.","main":"index.js","scripts":{"test":"node test.js"},"repository":{"type":"git","url":"git+https://github.com/coolaj86/node-safe-replace.git"},"keywords":["cluster","race","condition","file","write","replace","config","json"],"author":{"name":"AJ ONeal","email":"coolaj86@gmail.com","url":"https://coolaj86.com/"},"license":"(MIT OR Apache-2.0)","bugs":{"url":"https://github.com/coolaj86/node-safe-replace/issues"},"homepage":"https://github.com/coolaj86/node-safe-replace#readme","gitHead":"85d145d48791c87103ae6c1aa0131a69e9e284e3","_id":"safe-replace@1.0.0","_shasum":"beeab1cff61916d3f8821a9b806e38d9f838a4c2","_from":".","_npmVersion":"3.3.6","_nodeVersion":"5.0.0","_npmUser":{"name":"coolaj86","email":"coolaj86@gmail.com"},"maintainers":[{"name":"coolaj86","email":"coolaj86@gmail.com"}],"dist":{"shasum":"beeab1cff61916d3f8821a9b806e38d9f838a4c2","tarball":"https://registry.npmjs.org/safe-replace/-/safe-replace-1.0.0.tgz","integrity":"sha512-rS30VNm0hx9IyYw5RbYP7XdT4kzi0tRo70XjSgg8S/0pw50lLeH2jt1aPUxg8k9YehPB7seUnvmbv6a6kaFlhg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCCItIiV+Sw1BezErLHAsqdTbYw+Xb5U+NbO0twR1zZNQIgcziVYZAsinezBnUoFx7rm3L8V3qeA1GCGB2+tp3+UiQ="}]},"directories":{}},"1.0.1":{"name":"safe-replace","version":"1.0.1","description":"A micro-module for safely replacing a file.","main":"index.js","scripts":{"test":"node test.js"},"repository":{"type":"git","url":"git+https://github.com/coolaj86/node-safe-replace.git"},"keywords":["cluster","race","condition","file","write","replace","config","json"],"author":{"name":"AJ ONeal","email":"coolaj86@gmail.com","url":"https://coolaj86.com/"},"license":"(MIT OR Apache-2.0)","bugs":{"url":"https://github.com/coolaj86/node-safe-replace/issues"},"homepage":"https://github.com/coolaj86/node-safe-replace#readme","gitHead":"4d030c6216fabff3a4c6023965957bcd099f3719","_id":"safe-replace@1.0.1","_shasum":"7dc7b93ba82469529cb3c4fc9d84e63e5ecb4001","_from":".","_npmVersion":"3.3.6","_nodeVersion":"5.0.0","_npmUser":{"name":"coolaj86","email":"coolaj86@gmail.com"},"maintainers":[{"name":"coolaj86","email":"coolaj86@gmail.com"}],"dist":{"shasum":"7dc7b93ba82469529cb3c4fc9d84e63e5ecb4001","tarball":"https://registry.npmjs.org/safe-replace/-/safe-replace-1.0.1.tgz","integrity":"sha512-4zo+qeY0Q4MQ4eGVwS5vjXZ86pjDrakz786L/Scb0SG+7cLlISvMyHPUA5elFKLovd9jr6A6J/PuFImpxlJujw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDQurF3Uf9Wat6sBKOzU1k2T7Iga/1aG1nIsyUFKhlmSgIhAPlltfg8mcORVLBqc8r7ot/25i3L6VL0Lxn8jHv16dQr"}]},"directories":{}},"1.0.2":{"name":"safe-replace","version":"1.0.2","description":"A micro-module for safely replacing a file.","main":"index.js","scripts":{"test":"node test.js"},"repository":{"type":"git","url":"git+https://github.com/coolaj86/node-safe-replace.git"},"keywords":["cluster","race","condition","file","write","replace","config","json"],"author":{"name":"AJ ONeal","email":"coolaj86@gmail.com","url":"https://coolaj86.com/"},"license":"(MIT OR Apache-2.0)","bugs":{"url":"https://github.com/coolaj86/node-safe-replace/issues"},"homepage":"https://github.com/coolaj86/node-safe-replace#readme","gitHead":"7b8536d121a4d5e763262a6dc419024065631588","_id":"safe-replace@1.0.2","_shasum":"b181ab4095acdf6ab0a8f840517491ca8a9922ba","_from":".","_npmVersion":"3.3.6","_nodeVersion":"5.0.0","_npmUser":{"name":"coolaj86","email":"coolaj86@gmail.com"},"maintainers":[{"name":"coolaj86","email":"coolaj86@gmail.com"}],"dist":{"shasum":"b181ab4095acdf6ab0a8f840517491ca8a9922ba","tarball":"https://registry.npmjs.org/safe-replace/-/safe-replace-1.0.2.tgz","integrity":"sha512-MpcY3osIccSpsVtlCswRxt1qaWqcQoUCVtOD/4fap2BoJAE2b5jP32s2K6VTFHQBN03Gb9CGVwn77T0cTcW1nw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIAYkiaom2OSe7TJ5IS+SqGeeUQxtRHw5nSpmf76Hvs+lAiEAm12ud9Wk6/LjnAzkMiZqc9FaKfbvb2p0kS8Q+mGFZUQ="}]},"directories":{}},"1.0.3":{"name":"safe-replace","version":"1.0.3","description":"A micro-module for safely replacing a file.","main":"index.js","scripts":{"test":"node test.js"},"repository":{"type":"git","url":"https://git.coolaj86.com/coolaj86/fs-safe-replace.js.git"},"keywords":["cluster","race","condition","file","write","replace","config","json"],"author":{"name":"AJ ONeal","email":"coolaj86@gmail.com","url":"https://coolaj86.com/"},"license":"(MIT OR Apache-2.0)","bugs":{"url":"https://git.coolaj86.com/coolaj86/fs-safe-replace.js/issues"},"homepage":"https://git.coolaj86.com/coolaj86/fs-safe-replace.jse","gitHead":"b4466d937d10814ff1ed7a54b30b1fc28857046e","_id":"safe-replace@1.0.3","_npmVersion":"5.6.0","_nodeVersion":"10.2.1","_npmUser":{"name":"coolaj86","email":"coolaj86@gmail.com"},"dist":{"integrity":"sha512-WwK4IRO+MxMn+9UbnhdbCzf/cGTLTb6i4xAQhcl0K1J+Ij5pYfpQM0FPiRvR7S0624yPSp11RMHHIRPZW1sgAQ==","shasum":"46f7df9d1a98f036eed8ab989d2108b0fca6e9e4","tarball":"https://registry.npmjs.org/safe-replace/-/safe-replace-1.0.3.tgz","fileCount":5,"unpackedSize":17415,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbPIf5CRA9TVsSAnZWagAAmW4QAIldZhiNY/O2X8751h2M\nfRBRCviGQlLrqGXzxdwwvl+u8qDpLEdnjskanTunx9Ah3gts6meanXMrb/HM\n7vu4+a/2/uOv5ILgJQMBSPh0MO7ShYXAeVZjtaOa88Y7Ubzh0y2IAl+9Haj9\nKit1wMz4itiRG2uh938vjqllQLxl+X4lNkc3d6L8IKCJyPI0dc1lLTtL0kqX\nx3uPV5D4H4FWjcpmUfQHCUY63LK23NLPU7DvSU61kOgo3Hyq7VnJr5gd8uh+\no9W2RAZh+wckB8NhfBIJg3ZRuzzOCcA4CTm9Gw7CtuzgIQHqkA0pyRPGQpnl\n6A/9kLQNXA7TyPT1cboXMVMSJqcmtJJ/CzIAKhoSJNI3hJvcCVNtJ94O+C4Q\n0L+3zURmJ0VpnPKALr3LIzRgaDfDIk7ePkfexo7JsU3jIFbMPHHC6rxIy6uj\nQHvhxSX1L9Zq7UwUNuCVnXiDRGRx2X364YbNHl8FOsNrwBhEetpfkAF+yAwA\n14x6mIFtD6YWGZ9CVNHR3wxy3UOYlARg1mKpBZ4x94lF6O1vZ7aGEHWZdQM7\nY5VSAoU8e9+pA5/BLplvCAQ4Eno2KBVBQ5pOxyds3DjhhEXUHMvN04/KhMmS\ndGRCPpzTDVzvjGk9jJcpfSSDeabTc7uicdhh4IDII0g/eMFpig97Pw0R0E3D\n3KV/\r\n=Aiv3\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIDRDwqA1NGb2LXZ7KITFsBwKN9Yb3loCYBY603jJFAzqAiAWFKmogzb7nt7JZpONi4W3aPhMUMlwqDALfNbdc0Isnw=="}]},"maintainers":[{"name":"coolaj86","email":"coolaj86@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/safe-replace_1.0.3_1530693625570_0.8938222893237397"},"_hasShrinkwrap":false,"deprecated":"missing bluebird in package.json"},"1.0.4":{"name":"safe-replace","version":"1.0.4","description":"A micro-module for safely replacing a file.","main":"index.js","scripts":{"test":"node test.js"},"repository":{"type":"git","url":"https://git.coolaj86.com/coolaj86/fs-safe-replace.js.git"},"keywords":["cluster","race","condition","file","write","replace","config","json"],"author":{"name":"AJ ONeal","email":"coolaj86@gmail.com","url":"https://coolaj86.com/"},"license":"(MIT OR Apache-2.0)","bugs":{"url":"https://git.coolaj86.com/coolaj86/fs-safe-replace.js/issues"},"homepage":"https://git.coolaj86.com/coolaj86/fs-safe-replace.jse","dependencies":{"bluebird":"^3.5.2"},"gitHead":"3bfa3383b61a4359c90ee7acda3a076973d7756d","_id":"safe-replace@1.0.4","_npmVersion":"6.1.0","_nodeVersion":"10.6.0","_npmUser":{"name":"coolaj86","email":"coolaj86@gmail.com"},"dist":{"integrity":"sha512-6IMSb/eng0O5qDqHpGhfARtmYJu9PmoQy3COQ9AVwQlOBbH15K7CiPEchrEqJZmTcvpFiEwXjTMAPh0vqAqsxQ==","shasum":"3a7e05e236f77f31f72da643239d147cf5ef9832","tarball":"https://registry.npmjs.org/safe-replace/-/safe-replace-1.0.4.tgz","fileCount":5,"unpackedSize":17276,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbjYnECRA9TVsSAnZWagAAYB8P/3p0D9a1yq8Hs6M7XI7k\nXD3C5yD5RDB4QsXb3y6Kr03+AbLFShmGDjX2/zfvcelABjErzE1rtfTCLitq\nIRPaYYbqsZT36wcPGLbapGlI3EyqXBR+s31U6W50KC9yG9UFO3sO+5PCtQEo\nO8IuXdmlhcTFViSWkzM4wfk8oB5nGtkvsl1Nl4Y6hYgLJthya19d9zz37xNJ\n2Ox6LraiOY9UKfS7HQA1S/rFFgNeSlGuaU0EQXAUe3iVJP+udpoIKpD3ECjS\nIFktvnmfSvcQz72cwscfCLXJ7XjOwVEfB9m5PIOIHAQR7tmG3UC4AMKGmOmt\nQME9zgf+AHWG3RPSG98jOE8xZbxtLWc5q8+h9UOBTF0It26AMmamLj3b2yjN\n13UxL1rmrcqPZnPej26uTwXphaxsfgRVJPsbc2d1VK4cC4jnvZQbvW3QNUNr\ndVGD75kqtAyo7+JM744A+r2IN4uRsibi3zyJi9CIi6VuQ2piYNELg/q17mdU\nd2eDMxUNBJaWURoXLWK/zkkWUGoVt/bVplErToBiPKovEVhReBlQAD9dRk3y\nxMuCYOIqTJJmcNev8GpsVfFvE9H+bX568vk2SSbGqLB2suvfiHv3HqBd7hh/\nOnudECQMhPFGGrQGlvUR0NXaTT7t5xpadxoRDQYV08OvP4NZ7GPfVLWENF43\njb16\r\n=JfBA\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCcRDeXrzHrJWk2tPvi6Zi3VORSv5kF3Sxo01U97SJC5QIhALTpxHh815zinuN7A4zFpb6THX+PGFEdtOgmW/8ziQ7t"}]},"maintainers":[{"name":"coolaj86","email":"coolaj86@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/safe-replace_1.0.4_1536002499940_0.6090120211100709"},"_hasShrinkwrap":false},"1.1.0":{"name":"safe-replace","version":"1.1.0","description":"A micro-module for safely replacing a file.","main":"index.js","scripts":{"test":"node test.js"},"repository":{"type":"git","url":"https://git.coolaj86.com/coolaj86/fs-safe-replace.js.git"},"keywords":["cluster","race","condition","file","write","replace","config","json"],"author":{"name":"AJ ONeal","email":"coolaj86@gmail.com","url":"https://coolaj86.com/"},"license":"(MIT OR Apache-2.0)","bugs":{"url":"https://git.coolaj86.com/coolaj86/fs-safe-replace.js/issues"},"homepage":"https://git.coolaj86.com/coolaj86/fs-safe-replace.jse","gitHead":"54b295422952af449286827a1f7846a425961851","_id":"safe-replace@1.1.0","_npmVersion":"6.1.0","_nodeVersion":"10.6.0","_npmUser":{"name":"coolaj86","email":"coolaj86@gmail.com"},"dist":{"integrity":"sha512-9/V2E0CDsKs9DWOOwJH7jYpSl9S3N05uyevNjvsnDauBqRowBPOyot1fIvV5N2IuZAbYyvrTXrYFVG0RZInfFw==","shasum":"432821b5a8139a38b534678d712f0850fe3e5235","tarball":"https://registry.npmjs.org/safe-replace/-/safe-replace-1.1.0.tgz","fileCount":5,"unpackedSize":17811,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbjYnoCRA9TVsSAnZWagAArVUP/RJ9pBsnGovUfM9Nt1JO\nkPW7FsKanVR3HAhQw0qRWOJiuSnr3cH/Z0SqwpRlSLWIZI1QV9yYsg9sPWZJ\nHd/xYjFdrgGPl6T4XW7GfF6CQTmJePjTD7cvwdR73qzxGRglUk9xjOrXsMAA\nrRm2yltVxqmbrdlqd5nxiw8JurwIjipH85lP+1RFaeraOtk9vrxzlHPIhPQo\nrOIa0ivDAGQxLwS58RVEBjxcJI2ZonnWBfKrR0CP+nQC9IHiNglGkRvTB1QW\nHKpp6Yis2mAQThddKENsT5Gx8M1Im8HFMGMmKi9jZPHT9A4wTv2/eRKmZIqV\n09X3gLjjAhWRx6AWc9H2luK+O0aUdoRWT6y2BJqkxOm2afHy4NIHo539RPAJ\nfx5qDkfD2LOaFbUN6Cr7/zMNsTcJjklAoWC/eQoSjB2dJ/GONtZs83F43QhJ\nyd9bYOU8AWl+FNDlw0+QWzWUk3aDVLXhw29DHyYWjW5vTAzL5RKIGQHxLv8e\nVwa7LFoLc6aAnBOOtouTtdxuJGkJztrewwG6GSITJ/gUg8IUfH9CpqQvF7hP\ncazgE+qBcdlSQbcBSkEK3Jp6NemwH8vzE3nA1hYxRRP+UdzEEbxgkOzGEzj3\nMY09g0PBMW09heBpqGfGbDTWv/zrs5BzbF6uCmDgszpI+rMTnuAkCmL/xvT8\nyhmk\r\n=BtfS\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCICSlkwf16NtR9iOMAG11jKC+4sbeXISweClH2cwFeWZuAiEA0G2RdlBBc8WFr0obM2qauPS0XTaFZczzJGp2SrGLUAg="}]},"maintainers":[{"name":"coolaj86","email":"coolaj86@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/safe-replace_1.1.0_1536002535947_0.38815297465919096"},"_hasShrinkwrap":false}},"readme":"safe-replace\n============\n\nA micro-module for safely replacing a file.\n\nThis is intended to be generally safe even when a function that writes a file\nis accidentally called twice (as may happen with node cluster).\n\nCommandline Reference\n---------------------\n\nIf I want to safely replace a file with a new version, I would do so like this:\n\n```bash\n# create the new version\ntouch keep.txt.RANDOM.tmp\n\n# remove the previous backup\nrm -f keep.txt.bak\n\n# move the current version to the backup\nmv keep.txt keep.txt.bak\n\n# move the new version to the current\nmv keep.txt.RANDOM.tmp keep.txt\n```\n\nIf `keep.txt` became corrupt and I wanted to use the backup,\nI would do this:\n\n```bash\n# copy the backup to the new version\nrsync keep.txt.bak keep.txt\n```\n\nIn Node\n-------\n\nI ported that proccess to node.\n\n```\nsfs.writeFileAsync\nsfs.stageAsync\nsfs.commitAsync\nsfs.revertAsync\n```\n\n```js\n// default behavior is to concat (filename + '.' + rnd() + '.tmp')\nvar safeReplace = require('safe-replace').create({ tmp: 'tmp', bak: 'bak' });\n\nvar data = new Buffer('A priceless document');\nsafeReplace.writeFileAsync('keep.txt', data, 'ascii').then(function () {\n  fs.readdir('.', function (nodes) {\n    console.log('file system nodes', nodes);\n    // keep.txt\n    // keep.txt.bak\n  });\n});\n\n// let's say I want to write a tmp file and not commit it... weird\nsafeReplace.stageAsync('keep.txt', data, 'ascii').then(function (tmpname) {\n  fs.readdir('.', function (nodes) {\n    console.log('file system nodes', nodes);\n    // keep.txt.ac71teh8mja.tmp\n  });\n});\n\n// let's say I wrote keep.txt.x7t7sq926.tmp with my own mechanism\nsafeReplace.commitAsync('keep.txt.x7t7sq926.tmp', 'keep.txt').then(function () {\n  fs.readdir('.', function (nodes) {\n    console.log('file system nodes', nodes);\n    // keep.txt\n    // keep.txt.bak\n  });\n});\n\n// let's say I want to revert the file from the '.bak'\nsafeReplace.revertAsync('keep.txt').then(function () {\n  fs.readdir('.', function (nodes) {\n    console.log('file system nodes', nodes);\n    // keep.txt\n    // keep.txt.bak\n  });\n});\n```\n","maintainers":[{"name":"coolaj86","email":"coolaj86@gmail.com"}],"time":{"modified":"2022-06-26T15:20:14.547Z","created":"2015-12-15T06:10:42.952Z","1.0.0":"2015-12-15T06:10:42.952Z","1.0.1":"2015-12-15T06:35:46.893Z","1.0.2":"2015-12-15T07:06:22.145Z","1.0.3":"2018-07-04T08:40:25.622Z","1.0.4":"2018-09-03T19:21:40.104Z","1.1.0":"2018-09-03T19:22:16.026Z"},"homepage":"https://git.coolaj86.com/coolaj86/fs-safe-replace.jse","keywords":["cluster","race","condition","file","write","replace","config","json"],"repository":{"type":"git","url":"https://git.coolaj86.com/coolaj86/fs-safe-replace.js.git"},"author":{"name":"AJ ONeal","email":"coolaj86@gmail.com","url":"https://coolaj86.com/"},"bugs":{"url":"https://git.coolaj86.com/coolaj86/fs-safe-replace.js/issues"},"license":"(MIT OR Apache-2.0)","readmeFilename":"README.md"}