{"name":"rw-stream","version":"0.3.2","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":"node test"},"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":"^6.0.1","eslint-config-scramjet":"^2.0.0","scramjet":"^4.25.2"},"dependencies":{},"_resolved":"","_integrity":"","_from":"https://github.com/signicode/rw-stream/archive/v0.3.2.tar.gz","bugs":{"url":"https://github.com/signicode/rw-stream/issues"},"_id":"rw-stream@0.3.2","_nodeVersion":"12.4.0","_npmVersion":"6.9.0","dist":{"integrity":"sha512-z445mryinFKE8wlVnKwAMt5yqhs0AfexJ/zCNNxZmKRtWb8ybOOaXnzh4JutRaraOF6GpAben7X7DvMOCLLgWQ==","shasum":"02ff5b0853b5b7524efd0c205294184c45f47aa6","tarball":"http://registry-npm.ywwl.com/rw-stream/download/rw-stream-0.3.2.tgz","fileCount":19,"unpackedSize":1080742,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdFg3hCRA9TVsSAnZWagAABi8P/R3ztLGBysv6jJ2R6iHT\nujMPd9iqD/KKgoJhY8lKw9SDFmuo0vVe62626ba1+1XB+N/VWNczyDu+FzAy\n8hOrug8SZnINV0Pasvm2/YP07sZfrHnGuyxnO2E8bpLMW7YF/LQoscSxmibr\nz39vU39Z5T0H4pJHmL4XXeJlK3N3yqWQQNqZm2guDnfJkycj9a/8Msk8HaaQ\nCUk1q1JosN1+lGPwW6UPQnc+HqYrMiBWPU6+/SeZYLPA9Ny4IDy6wyj9oxzg\nMjknuS+MuvBVXlxS+E8Rm701UwTbEPV8JIZp2SyrWeYcyQpYxOC577W6FObU\n4NdaboLlg4jgTtxdeQAJq864AyuSBXA79gRIXnJRhHAnVVrGVvPom/HSD399\n/O+s0BCAJ7g34NWKX9uMhLZ5YdFFGNH+rIk2MfbROyhng2QTKHv70ti5pjx7\nPilka7WiSq0pDNFYuCxor34p110AKgevd0duYtZ4UxQ3tGDqGYyTd97baK4A\nSjj88Yq6Hv98REtVLwAGYzBc9a6XkOW9MZj0oG6esppmcwqEmOAbsRfxMNV9\nhblu8qLnkNZ69YZyP6NHEgZYq4pNbL2OcDzE5dZwd9iSixW3zrpFHB9sIIMk\n4uQR6cd8esINA4q/3k/GrkBpBkq2PLRU3CODdXADLYBqglBh70RFd8+oV/yt\nhoci\r\n=ETmC\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC+O8hA3r3ZrEuLQ+dDAV4t6OsDAMA8JnBjEld7iuH8dgIgHjK27qmWk0e9LN682UVaxVN6zP1XlMFsgL9fVBa1m7g="}],"size":28804,"noattachment":false,"key":"/rw-stream/-/rw-stream-0.3.2.tgz"},"maintainers":[{"name":"michalcz","email":"cz@signicode.com"}],"_npmUser":{"name":"michalcz","email":"cz@signicode.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/rw-stream_0.3.2_1561726433242_0.21887002764823404"},"_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":1561726433382,"_cnpm_publish_time":1561726433382,"dist-tags":{"latest":"0.3.3"}}