GithubHelp home page GithubHelp logo

ssb-content-stream's Introduction

ssb-content-stream

Scuttlebutt stream of messages and off-chain content.

This plugin exposes a method that wraps createHistoryStream and returns all off-chain content referenced by those messages. This gives us the ability to do deletion and feed replication without using the blob system.

Usage

const server = require('ssb-server')
  .use(require('ssb-master'))
  .use(require('./'))

const config = Object.assign({}, require('ssb-config'), {
  keys: require('ssb-keys').generate() // Random key for testing!
})

const ssb = server(config)

ssb.contentStream.publish({ type: 'test', randomNumber: 42 }, (err, msg) => {
  if (err) throw err
  console.log(msg.value.content)
})
{ type: 'content',
  href:
   'ssb:content:sha256:rWqRaMb0dfFmss2xan936taWQFfJ_1GGOeckZrFUit8=',
  mediaType: 'text/json' }

API

createSource(opts)

Wrapper for createHistoryStream() that prepends all off-chain content to the stream. Since createHistoryStream() only returns public and unencrypted messages this function will only return public messages and its content.

createHandler(cb)

Creates a through-stream that filters content out of the stream, adds them to the content store, and only passes the original metadata message through the stream.

getContent(msg, cb)

Takes a full message ({ key, value: { previous, sequence, ... } }) and returns the extracted content from that message in msg.value.content as if it wasn't a message with off-chain content.

`getContent(opts)

Passes createSource() through createHandler() and getContent().

publish(content, cb)

Wraps ssb.publish() to publish off-chain messages that can be accessed with content streams. Message schema is:

{
  "href": "ssb:content:sha256:rWqRaMb0dfFmss2xan936taWQFfJ_1GGOeckZrFUit8=",
  "mediaType": "text/json",
  "type": "content"
}

Installation

With npm:

npm install ssb-content-stream

With yarn:

yarn add ssb-content-stream

See Also

License

ISC

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.