https://github.com/fraction/ssb-content-stream
stream method to get both blobs and content
https://github.com/fraction/ssb-content-stream
Last synced: 3 months ago
JSON representation
stream method to get both blobs and content
- Host: GitHub
- URL: https://github.com/fraction/ssb-content-stream
- Owner: fraction
- Created: 2019-04-19T22:42:44.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2022-12-03T11:38:39.000Z (over 3 years ago)
- Last Synced: 2025-04-07T01:11:20.435Z (about 1 year ago)
- Language: JavaScript
- Size: 666 KB
- Stars: 5
- Watchers: 1
- Forks: 2
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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
```javascript
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)
})
```
```javascript
{ type: 'content',
href:
'ssb:content:sha256:rWqRaMb0dfFmss2xan936taWQFfJ_1GGOeckZrFUit8=',
mediaType: 'text/json' }
```
## API
### createSource(opts)
Wrapper for [`createHistoryStream()`][0] 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:
```json
{
"href": "ssb:content:sha256:rWqRaMb0dfFmss2xan936taWQFfJ_1GGOeckZrFUit8=",
"mediaType": "text/json",
"type": "content"
}
```
## Installation
With [npm](https://npmjs.org/):
```shell
npm install ssb-content-stream
```
With [yarn](https://yarnpkg.com/en/):
```shell
yarn add ssb-content-stream
```
## See Also
- [Scuttlebutt Protocol Guide](https://ssbc.github.io/scuttlebutt-protocol-guide/)
- [ssb-db](https://github.com/ssbc/ssb-db)
- [ssb-blob-content](https://gitlab.com/christianbundy/ssb-blob-content)
## License
ISC
[0]: https://github.com/ssbc/ssb-db#ssbdbcreatehistorystream-id-feedid-seq-int-live-bool-limit-int-keys-bool-values-bool---pullsource