{"action":"opened","issue":{"url":"https://api.github.com/repos/pull-stream/pull-stream/issues/81","repository_url":"https://api.github.com/repos/pull-stream/pull-stream","labels_url":"https://api.github.com/repos/pull-stream/pull-stream/issues/81/labels{/name}","comments_url":"https://api.github.com/repos/pull-stream/pull-stream/issues/81/comments","events_url":"https://api.github.com/repos/pull-stream/pull-stream/issues/81/events","html_url":"https://github.com/pull-stream/pull-stream/issues/81","id":186746321,"number":81,"title":"making a through stream and a writable stream appear as a through stream, and append a chunk to the end","user":{"login":"m59peacemaker","id":4369247,"avatar_url":"https://avatars.githubusercontent.com/u/4369247?v=3","gravatar_id":"","url":"https://api.github.com/users/m59peacemaker","html_url":"https://github.com/m59peacemaker","followers_url":"https://api.github.com/users/m59peacemaker/followers","following_url":"https://api.github.com/users/m59peacemaker/following{/other_user}","gists_url":"https://api.github.com/users/m59peacemaker/gists{/gist_id}","starred_url":"https://api.github.com/users/m59peacemaker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/m59peacemaker/subscriptions","organizations_url":"https://api.github.com/users/m59peacemaker/orgs","repos_url":"https://api.github.com/users/m59peacemaker/repos","events_url":"https://api.github.com/users/m59peacemaker/events{/privacy}","received_events_url":"https://api.github.com/users/m59peacemaker/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-11-02T09:11:08Z","updated_at":"2016-11-02T09:11:08Z","closed_at":null,"body":"I have a transform stream and a writable stream that both need to read from stdin. The transform stream transforms chunks and emits them (as usual). The writable stream collects some information from the stream and has a `getInfo()` function that can be called to retrieve that information. This is what my current code looks like, with `mergeStreams` being a hacky mess to make it work:\r\n\r\n```js\r\nconst myStream = () => {\r\n  const transformStream = foo()\r\n  const writableStream = bar()\r\n  const stream = mergeStreams([transformStream, writableStream], (push, cb) => { // flush function\r\n    // add some output to the end of the stream\r\n    push('\\n' + writableStream.getInfo() + '\\n')\r\n    cb() // stream is done\r\n  })\r\n  stream.push('\\n') // start with a blank line\r\n  return stream\r\n}\r\n\r\nprocess.stdin\r\n  .pipe(myStream())\r\n  .pipe(process.stdout)\r\n\r\n// sample output:\r\n/*                // blank line\r\n * output from transformStream\r\n * output from transformStream\r\n * and so on from transformStream\r\n * and finally the result from writableStream.getInfo()\r\n */\r\n```\r\n\r\nand here's a rundown of the stream logic\r\n\r\n```js\r\n/* stream is writable/readable\r\n  on write, chunks go to transformStream and writableStream\r\n  transformStream receives, transforms, and emits values\r\n  when the writer is finished writing to the stream\r\n    and transformStream is done reading/writing\r\n    and writableStream is done reading,\r\n    emit result of writableStream.getInfo()\r\n*/\r\n```\r\n\r\nI made this work with node streams by proxying the chunks to the other streams and using the flush function and events. It's complex and awkward behind the scenes. I hope that with pull-stream, I can get rid of that hacky `mergeStreams` function and do this with some pull-stream modules. I can't find a way to return a single stream that writes to both `transformStream` and `writableStream` and to inject the results of `getInfo()` at the end.\r\n\r\nThanks for any advice on this!"}}
{"actor":{"display_login":"m59peacemaker"}}