{"_id":"rw-stream","_rev":"359105","name":"rw-stream","description":"A simple stream that allows reading and writing to the same file at the same time.\u001b[H\u001b[C\u001b[F","dist-tags":{"latest":"0.3.3"},"maintainers":[{"name":"michalcz","email":"budleigh.salteron@gmail.com"}],"time":{"modified":"2021-07-13T08:44:31.000Z","created":"2018-11-05T18:44:45.502Z","0.3.3":"2019-07-22T17:59:53.625Z","0.3.2":"2019-06-28T12:53:53.382Z","0.3.1":"2019-06-12T17:00:39.255Z","0.3.0":"2018-11-05T18:44:45.502Z"},"users":{},"author":{"name":"Signicode","email":"open-source@signicode.com"},"repository":{"type":"git","url":"git+https://github.com/signicode/rw-stream.git"},"versions":{"0.3.3":{"name":"rw-stream","version":"0.3.3","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.1.0","eslint-config-scramjet":"^2.0.0","scramjet":"^4.25.5"},"dependencies":{},"_resolved":"","_integrity":"","_from":"https://github.com/signicode/rw-stream/archive/v0.3.3.tar.gz","bugs":{"url":"https://github.com/signicode/rw-stream/issues"},"_id":"rw-stream@0.3.3","_nodeVersion":"12.4.0","_npmVersion":"6.10.1","dist":{"shasum":"2403819737fec3a50a668b3aa33c59dc5c6c0c05","size":28938,"noattachment":false,"key":"/rw-stream/-/rw-stream-0.3.3.tgz","tarball":"http://registry.cnpm.dingdandao.com/rw-stream/download/rw-stream-0.3.3.tgz"},"maintainers":[{"name":"michalcz","email":"budleigh.salteron@gmail.com"}],"_npmUser":{"name":"michalcz","email":"cz@signicode.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/rw-stream_0.3.3_1563818393507_0.672873957533697"},"_hasShrinkwrap":false,"publish_time":1563818393625,"_cnpm_publish_time":1563818393625},"0.3.2":{"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":{"shasum":"02ff5b0853b5b7524efd0c205294184c45f47aa6","size":28804,"noattachment":false,"key":"/rw-stream/-/rw-stream-0.3.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/rw-stream/download/rw-stream-0.3.2.tgz"},"maintainers":[{"name":"michalcz","email":"budleigh.salteron@gmail.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,"publish_time":1561726433382,"_cnpm_publish_time":1561726433382},"0.3.1":{"name":"rw-stream","version":"0.3.1","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":"^5.16.0","eslint-plugin-node":"^9.1.0","scramjet":"^4.25.1"},"dependencies":{},"_resolved":"","_integrity":"","_from":"https://github.com/signicode/rw-stream/archive/v0.3.1.tar.gz","bugs":{"url":"https://github.com/signicode/rw-stream/issues"},"_id":"rw-stream@0.3.1","_nodeVersion":"12.4.0","_npmVersion":"6.9.0","dist":{"shasum":"e1967799e68018db4988c213fb8a1bf59f6f06a7","size":28457,"noattachment":false,"key":"/rw-stream/-/rw-stream-0.3.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/rw-stream/download/rw-stream-0.3.1.tgz"},"maintainers":[{"name":"michalcz","email":"budleigh.salteron@gmail.com"}],"_npmUser":{"name":"michalcz","email":"cz@signicode.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/rw-stream_0.3.1_1560358839098_0.36863297593359"},"_hasShrinkwrap":false,"publish_time":1560358839255,"_cnpm_publish_time":1560358839255},"0.3.0":{"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":{"shasum":"36fc3036d587f5d14cead583b33ed799e6c88afd","size":27277,"noattachment":false,"key":"/rw-stream/-/rw-stream-0.3.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/rw-stream/download/rw-stream-0.3.0.tgz"},"maintainers":[{"name":"michalcz","email":"budleigh.salteron@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/rw-stream_0.3.0_1541443485400_0.9014014891697635"},"_hasShrinkwrap":false,"publish_time":1541443485502,"_cnpm_publish_time":1541443485502}},"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","_attachments":{},"homepage":"https://github.com/signicode/rw-stream","bugs":{"url":"https://github.com/signicode/rw-stream/issues"},"license":"MIT"}