{"id":13798002,"url":"https://github.com/jprichardson/electron-ipc-stream","last_synced_at":"2025-03-16T19:31:40.052Z","repository":{"id":38355637,"uuid":"38938407","full_name":"jprichardson/electron-ipc-stream","owner":"jprichardson","description":"Duplex stream that runs over Electron's IPC","archived":false,"fork":false,"pushed_at":"2016-03-19T19:52:08.000Z","size":10,"stargazers_count":152,"open_issues_count":2,"forks_count":14,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-10-12T18:08:58.761Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jprichardson.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-07-11T19:50:14.000Z","updated_at":"2024-08-07T07:03:13.000Z","dependencies_parsed_at":"2022-08-29T04:10:06.388Z","dependency_job_id":null,"html_url":"https://github.com/jprichardson/electron-ipc-stream","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jprichardson%2Felectron-ipc-stream","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jprichardson%2Felectron-ipc-stream/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jprichardson%2Felectron-ipc-stream/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jprichardson%2Felectron-ipc-stream/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jprichardson","download_url":"https://codeload.github.com/jprichardson/electron-ipc-stream/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221667295,"owners_count":16860592,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-04T00:00:37.721Z","updated_at":"2024-10-27T11:09:40.422Z","avatar_url":"https://github.com/jprichardson.png","language":"JavaScript","funding_links":[],"categories":["Library","Tools"],"sub_categories":["IPC","For Electron"],"readme":"electron-ipc-stream\n===================\n\nDuplex stream that run over [Electron's IPC](https://github.com/atom/electron/tree/master/docs) mechanism.\n\n\nWhy?\n---\n\nThis allows you to use any Node.js stream readable/writable and easily communicate between your\nmain/renderer process.\n\nSince your `renderer` process is also responsible for UI/DOM, etc, you may not want to do any heavy\nprocessing on the renderer process. You could leverage this module to have the renderer stream\ndata to the `main` process for processing and then the `main` module could stream results\nback to the `renderer` process for consumption.\n\n\nInstall\n-------\n\n    npm i --save electron-ipc-stream\n\n\nUsage\n-----\n\n### Example 1: Pipe file from main process to renderer.\n\n**main.js:**\n\n```js\nvar app = require('app')\nvar fs = require('fs')\nvar path = require('path')\nvar window = require('electron-window')\nvar IPCStream = require('electron-ipc-stream')\n\napp.on('ready', function () {\n  var win = window.createWindow({ height: 600, with: 1000 })\n\n  var ipcs = new IPCStream('any-arbitrary-channel-name', win)\n  win.showUrl(path.resolve(__dirname, './index.html'), function () {\n    // window is visible, dom is ready in window\n    fs.createReadStream('/tmp/mainfile').pipe(ipcs)\n  })\n})\n```\n\n**rend.js:**\n\n```js\nvar fs = require('fs')\nvar ipc = require('ipc')\nvar IPCStream = require('electron-ipc-stream')\nvar ipcs = new IPCStream('any-arbitrary-channel-name')\n\ndocument.addEventListener('DOMContentLoaded', function () {\n  ipcs.pipe(fs.createWriteStream('/tmp/rendfile')).on('finish', function () {\n    console.log('done')\n  })\n})\n```\n\n\n### Example 2: Pipe file from renderer process to main.\n\n**main.js:**\n\n```js\nvar app = require('app')\nvar fs = require('fs')\nvar path = require('path')\nvar window = require('electron-window')\nvar IPCStream = require('electron-ipc-stream')\n\nvar tmpfile = '/tmp/mainfile'\napp.on('ready', function () {\n  var win = window.createWindow({ height: 600, with: 1000 })\n  var ipcs = new IPCStream('any-arbitrary-channel-name', win)\n  ipcs.pipe(fs.createWriteStream(tmpfile)).on('finish', function () {\n    console.log('done')\n  })\n  win.showUrl(path.resolve(__dirname, './index.html'), function () { })\n})\n```\n\n**rend.js:**\n\n```js\nvar crypt = require('crypto') // notice this is 'crypt' and not 'crypto'\nvar fs = require('fs')\nvar ipc = require('ipc')\nvar IPCStream = require('electron-ipc-stream')\nvar ipcs = new IPCStream('any-arbitrary-channel-name')\n\nfs.writeFileSync('/tmp/rendfile', crypt.randomBytes(10000))\ndocument.addEventListener('DOMContentLoaded', function () {\n  fs.createReadStream(tmpfile).pipe(ipcs)\n})\n```\n\n\nAPI\n----\n\n### Main Process\n\n#### IPCStream(channel, [browserWindow], [streamOptions])\n\nCreate a new IPCStream in the `main` process.\n\n\n### Renderer Process\n\n#### IPCStream(channel, [streamOptions])\n\nCreate a new IPCStream in the `renderer` process.\n\n\n### Stream Options\n\nYou shouldn't have to mess with `objectMode`. Under the hood, `objectMode` is `true`.\nBuffers are serialized to JSON. This is because of the way that Electron handles buffers\nin renderer. See: https://github.com/atom/electron/blob/master/docs/api/remote.md for\nmore detail. You also may need to adjust [`highWaterMark`](https://nodejs.org/api/stream.html).\n\n\n### JSON Objects\n\nIt is completely safe to call `write` on either end of the stream with objects.\n\nsource:\n\n```js\nmyStream.write({name: 'JP'})\n```\n\ndest:\n\n```js\n// streams 1 (flowing):\nmyStream.on('data', function (data) {\n  console.dir(data) // =\u003e {name: 'JP'}\n})\n\n// streams 2/3 (pull, if you prefer):\nmyStream.on('readable', function () {\n  var data\n  while (null !=== (data = myStream.read())) {\n    console.dir(data) // =\u003e {name: 'JP'}\n  }\n})\n\n```\n\n\n\n### Examples\n\nIn the `./test` folder, you'll see two examples. You can run these by\ninstalling [electron-prebuilt](https://www.npmjs.com/package/electron-prebuilt):\n\n    npm i -g electron-prebuilt\n    electron ./test/main-to-rend\n    electron ./test/rend-to-main\n\n\n\nLicense\n-------\n\nMIT Copyright [JP Richardson](https://github.com/jprichardson)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjprichardson%2Felectron-ipc-stream","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjprichardson%2Felectron-ipc-stream","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjprichardson%2Felectron-ipc-stream/lists"}