{"id":22753590,"url":"https://github.com/starryinternet/missive","last_synced_at":"2025-04-14T15:30:57.646Z","repository":{"id":57298351,"uuid":"59676239","full_name":"StarryInternet/missive","owner":"StarryInternet","description":"Fast, lightweight library for encoding and decoding JSON messages over streams.","archived":false,"fork":false,"pushed_at":"2019-02-19T14:08:19.000Z","size":32,"stargazers_count":20,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-13T23:54:04.868Z","etag":null,"topics":["decoding-json-messages","javascript","json","message-framing","socket","stream","tcp"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/StarryInternet.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-05-25T15:43:02.000Z","updated_at":"2025-04-12T14:09:47.000Z","dependencies_parsed_at":"2022-09-06T04:20:47.981Z","dependency_job_id":null,"html_url":"https://github.com/StarryInternet/missive","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StarryInternet%2Fmissive","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StarryInternet%2Fmissive/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StarryInternet%2Fmissive/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StarryInternet%2Fmissive/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/StarryInternet","download_url":"https://codeload.github.com/StarryInternet/missive/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248906392,"owners_count":21181171,"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":["decoding-json-messages","javascript","json","message-framing","socket","stream","tcp"],"created_at":"2024-12-11T06:11:50.139Z","updated_at":"2025-04-14T15:30:57.619Z","avatar_url":"https://github.com/StarryInternet.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# missive\n\n[![Build Status](https://travis-ci.org/StarryInternet/missive.svg?branch=master)](https://travis-ci.org/StarryInternet/missive)\n\nFast, lightweight library for encoding and decoding JSON messages over streams.\n\nBuilt using [fringe](https://github.com/StarryInternet/fringe)\n\n### Installing\n\n```\nnpm install --save missive\n```\n\n### How it works\n\nRather than simply using newlines to delimit messages, `missive` uses the\ntime-honored tradition of length prefixing. We think this is safer, and it\ncan also be quite a bit faster.\n\n### Examples\n\n##### Piping data\n\n`missive` exports just two functions, `encode()` and `parse()`. Each returns\nan instance of `Stream.Transform`.\n\nBoth streams pipe `Buffer` instances on the way out (like pretty much\nall streams), but `encode` expects an object to be passed to `write`.\n\n```js\nlet missive = require('missive');\n// create an encoder stream\nlet encode = missive.encode();\n// create a parser stream\nlet parse = missive.parse();\n\nencode.pipe( parse ).pipe( process.stdout );\n\nencode.write({ hello: 'world' }); // should log {\"hello\": \"world\"}\n```\n\n##### `data` events\n\nBoth streams implement standard `data` events, which emit `Buffer` instances.\n\n```js\nlet missive = require('missive');\nlet encode = missive.encode();\nlet parse = missive.parse();\n\nparse.on( 'data', buffer =\u003e {\n  console.log( buffer instanceof Buffer ); // true\n});\n\nencode.write({ foo: 'bar' });\n```\n\n##### `message` event\n\nThe `parse` stream also implements a custom `message` event for convenience.\nRather than emitting a `Buffer` instance, the `message` event emits a parsed\nJavaScript object.\n\n```js\nlet missive = require('missive');\nlet encode = missive.encode();\nlet parse = missive.parse();\n\nparse.on( 'message', obj =\u003e {\n  console.log( obj.foo ); // 'bar'\n});\n\nencode.write({ foo: 'bar' });\n```\n\n##### Writing to sockets\n\n```js\nlet net = require('net');\nlet missive = require('missive');\nlet server = net.createServer();\n\nserver.listen( 1337 );\n\nserver.on( 'connection', socket =\u003e {\n  let encode = missive.encode();\n  encode.pipe( socket );\n  encode.write({ hello: 'world' });\n});\n```\n\n##### Reading from sockets\n\n```js\nlet net = require('net');\nlet missive = require('missive');\nlet client = net.createConnection({ port: 1337 });\n\nclient.pipe( missive.parse() ).on( 'message', obj =\u003e {\n  console.log( obj ); // { hello: 'world' }\n});\n```\n\n##### Compression\n\nTo enable Node's `zlib` compression, instantiate an `encode` stream\nwith `{ deflate: true }` and a `parse` stream with `{ inflate: true }`\n\nNote that this will incur a fairly substantial performance penalty, so\ncompression is only advised in situations where message volume is low\nand saving bytes over the wire is critical.\n\n```js\nlet missive = require('missive');\nlet encode = missive.encode({ deflate: true });\nlet parse = missive.parse({ inflate: true });\n\nparse.on( 'message', obj =\u003e {\n  console.log( obj.foo ); // 'bar'\n});\n\nencode.write({ foo: 'bar' });\n```\n\n### Spec\n\nIn case you can't use `missive` on one side of a socket, this is\nhow it encodes data:\n\n1. Let `data` be the result of `JSON.stringify( object ) + '\\n'`.\n2. Let `header` be the string `'JSON'` as a utf-8 string.\n3. Let `byteLength` be the byte length of `data` as utf-8.\n4. Let `buffer` be a new buffer of length `byteLength + 8`.\n5. Write `header` at byte offset `0` of `buffer` as a UInt32LE.\n6. Write `byteLength` at byte offset `4` of `buffer` as a UInt32LE.\n7. Write `data` at byte offset `8` of `buffer` as a utf-8 string.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstarryinternet%2Fmissive","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstarryinternet%2Fmissive","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstarryinternet%2Fmissive/lists"}