{"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":{"integrity":"sha512-yRrLkuJ3PeQYw1gJ2U9Wn9htgwTeYbLUSoeTNwJ4odOTwaM4EMTG4gKdkRTYa6qCsAWxHmJcjjguV4BR78z+8A==","shasum":"e1967799e68018db4988c213fb8a1bf59f6f06a7","tarball":"http://registry-npm.ywwl.com/rw-stream/download/rw-stream-0.3.1.tgz","fileCount":19,"unpackedSize":1079436,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdAS+3CRA9TVsSAnZWagAAJ8UQAIhXY1hScfZz1379g0b8\n9E+bdwDJ1OEFUrPWytOGK9GPD9YIwwjdmXp1aVVbQF05fJQMn/gIX7zBsIis\nNaqtew+S14S0+GH1MQWSD43K5qfvsJSJZdfF1swCryiQMIqk/sl+zdkF4FVe\nHFhhXfAEkqyOT6ccWsOvKVpOlGZlqAWh1ZhzX4szaO577N8VyT8KPo3PNJ8B\n2iHdEwQjC6gyj2yChoQ6KzfC2L1oMdGaAffC7gsFmalqexjt1adal6MJSdn5\n9HXt3ufJfy+uPE9iANMZi+okkWX+WZbNEC4XqosV6w2yR8oBOv92OmvtQ0kD\nJqD6Xfz37xA3K5u5yIb6NQ97gbmT3cEpTfG1ybymNP652sK2/sHmchqnNVsy\neANK0wBHlXMkMxl7WL1vvKIbCyYDpfA4Ljc7WwKGpSwK0Fu3FZF9+6TIbloE\nGBES3QK1eUn0tHs27wWM/HJ6q4I1soCECEKIg8/axesvqAJVDtQ22yvgrwbU\nqlqnJsLl7dAG6Kb1LT95d37v6g2K/IEX0p1yyuM8Uo1B0mADHs8eJIqrQAEV\nwwz3M/AOGTt2E9Ba2Djhk1c7vIi9cueIS7A7zR1Rce9FAUYMhgKaeqppVdeG\nAgYRpTqHYS/CByKeTq34qxQJk+VVZpqn1IUM5sV3J2CvUiqCZT+jkZEJ0g4F\nivQt\r\n=UxdI\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIA4jrZsfuHwrvmowEH+68+kzWXTAd0I39W7wQhLBy5sYAiEAuftAFFQXuol1K3MsGbRl0efcM+DSz5KDuv/k8kIa5kI="}],"size":28457,"noattachment":false,"key":"/rw-stream/-/rw-stream-0.3.1.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.1_1560358839098_0.36863297593359"},"_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":1560358839255,"_cnpm_publish_time":1560358839255,"dist-tags":{"latest":"0.3.3"}}