{"name":"rw-stream","version":"0.3.0","description":"A simple stream that allows reading and writing to the same file at the same time.\u001b[H\u001b[C\u001b[F","main":"index.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"author":{"name":"Signicode","email":"open-source@signicode.com"},"license":"MIT","homepage":"https://github.com/signicode/rw-stream","repository":{"type":"git","url":"git+https://github.com/signicode/rw-stream.git"},"engines":{"node":">=8.6.0"},"keywords":["stream","streams","async","await","transform","replace","fs","write","pipe"],"devDependencies":{"eslint":"^5.6.1","eslint-plugin-node":"^7.0.1","scramjet":"^4.18.14"},"dependencies":{},"_resolved":"","_integrity":"","_from":"https://github.com/signicode/rw-stream/archive/v0.3.0.tar.gz","bugs":{"url":"https://github.com/signicode/rw-stream/issues"},"_id":"rw-stream@0.3.0","_npmVersion":"6.4.1","_nodeVersion":"10.11.0","_npmUser":{"name":"michalcz","email":"cz@signicode.com"},"dist":{"integrity":"sha512-l9Biu1dKNjBdL8WS/lRjWLqET4TpOGTWaMYUoqHAa//2lBqiUnjfdV9whRqqbFGEdDBpcrmKWmpCmlLMsu4T9Q==","shasum":"36fc3036d587f5d14cead583b33ed799e6c88afd","tarball":"http://registry-npm.ywwl.com/rw-stream/download/rw-stream-0.3.0.tgz","fileCount":13,"unpackedSize":1077547,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJb4I+eCRA9TVsSAnZWagAAzAUP/1p9PM0wIUwMz6N/VEsN\nXyjgipY/Jze50kQLqYIcB4Fh3pNRPmSsCZ8U+bUNPN42pLyjRKaFT1tQM43d\nQFGJE6xUCRpa2n5G2LXrtF4vgNpGlUcG6+mLbiSFoiEWaSjSJAUolvBcbhGd\nswGIVSndQfuCIbfF60inl7rE4dMurdFuBRiP1qUOm9tfsm5G6foHYNtFhqTE\nfWhzi1U7p5jtionJVNp3r2zqBcNVYB0pMW2b1rSu9kpVP8KUotAGqyOx1uYd\nEWmsuQqVoT3FtyytNYGQ4o0WpKl+ef3/YoZy/0yz4sCl0RNZ2kmwa0ueYIWO\nqWtHX+fG267iZDMoOJ5rlRzj9CYElaHDR6HDUbFSZB8uSA1vmYER1DVhiYI7\nWUOZm2CjuL/+2hin3/DvMh690rER1robMXQSvncimWNtkMBNSXwuEz3ye+L4\nMFUofc0wxqGXexaVV3pnIOeHm5IB4HTRvCkoHQu4H/TehFGltto1Z0qYQKmW\n2SLn9oVbsGHE2d9Vt0bk+C7ptn/Q3jcoiWRkrbU0KdBEQncLW8Ddd3zkHapb\n0jPrWYozJV9MICAITVIC+zBw4DRzt5D/D/UUB76RfqoaWRxEiHYeVLizgOJJ\nAEbbhk8sa9OX7mwPN5egsOnTy5w2rREQLOp2SX38nFJLGQIdxbb8Lf3Fvd+G\nkYpQ\r\n=o02v\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDVKeXIxG6/YHUdRQUOobumlmKIccPFQJxMNCYh2tTMGQIhAJ85T8jkXTVoXJbe+Y8UcuGNCTxOuqVMB5W8y3fy8nfF"}],"size":27277,"noattachment":false,"key":"/rw-stream/-/rw-stream-0.3.0.tgz"},"maintainers":[{"name":"michalcz","email":"cz@signicode.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/rw-stream_0.3.0_1541443485400_0.9014014891697635"},"_hasShrinkwrap":false,"readme":"# rw-stream\n\nA stream that can substitute contents of a file in streaming fashion.\n\nThe aim of this module is to expose a readable and writable stream connected to a single file at the same time. It works similarily to `fs.createReadStream` and `fs.createWriteStream`, but allows writing and reading simultanously, without creating a new file or move operations.\n\nThis is achieved by disallowing any write operations to advance further than the current reading index. This module will then make sure that a byte of the file will be read before it's overwritten.\n\n***Note:*** In any case, the file will be accessed and it's contents may be overwritten even if there's no actual read operation done (due to node.js streams buffering mechanisms).\n\n## Usage:\n\n```javascript\nconst rw = require(\"../\");\n\nconst {fd, readStream, writeStream} = await rw(path, options);\n```\n\nArguments:\n\n * **path** `string` - the path of the file to access.\n * **options** `object` - options, currently none.\n\nReturns an `object` with the following properties:\n\n * **fd** `int` - file descriptor number (from `fs.open`)\n * **writeStream** `Writable` - Writable stream for new file contents.\n * **readStream** `Readable` - Readable stream containing previous contents.\n\n## Samples\n\nA simple module that replaces the contents of a file while keeping a backup:\n\n```javascript\nconst replaceAndBackup = async (newContentStream) => {\n    const {readStream, writeStream} = await rw(path);\n\n    readStream.pipe(fs.createWriteStream(`${path}.bak`));\n    newContentStream.pipe(writeStream);\n\n    return new Promise((res, rej) => writeStream.on('finish', res).on('error', rej));\n}\n```\n\n## Testing\n\nFor now there's just:\n\n```bash\n$ node test\n```\n\nTwo tests will be executed:\n\n* one for file that's being grown.\n* one for file that's being shrinked.\n\nWe're working on more and proper tests.\n","publish_time":1541443485502,"_cnpm_publish_time":1541443485502,"dist-tags":{"latest":"0.3.3"}}