1.0.0 • Published 3 years ago

slashtags-feed-reader v1.0.0

Weekly downloads
-
License
-
Repository
github
Last release
3 years ago

slashtags-feed-reader

Collection of helper functions to read Slashtags feeds from a Hyperdrive.

Supported feeds:

feed nameknown asurl
Bitfinex Bitcoin Pricepriceslashfeed:kgw7hqj4usek78smxczgrcxqn313s7qnpnc7so7guegziwjic6yy#encryptionKey=nds189gg3hgpei45y79f9ho6s6yh4sm3su1bw4yktt9gtggxtxty
Bitcoin InfoBlocksslashfeed:gpjjokcczfyitc1phrr5x3t6ac5friifderx6ot51mtkjmn9seqo#encryptionKey=jo6nybw8f3hzwea8jzcoyiymgimhfo4ftao93jxcinurgfrcxaay
Bitcoin HeadlinesHeadlinesslashfeed:jh7fzqcngzwq79e645x8p81kpn5ch8ybi6n4d571jyczd3qr1psy#encryptionKey=yrrfn8n3guaonho4oafgic7xcmbjwfhb6ihxguqjaqf1mwhpxeco

Install

npm install slashtags-feed-reader

Usage

Open Hyperdrive

import { SDK, SlashURL } from '@synonymdev/slashtags-sdk'

const sdk = new SDK()

const parsed = SlashURL.parse(url);
const key = parsed.key;
const encryptionKey =
  typeof parsed.privateQuery.encryptionKey === "string"
    ? SlashURL.decode(parsed.privateQuery.encryptionKey)
    : undefined;

const drive = sdk.drive(key, { encryptionKey });

Use the corrisponding reader function

import feedReaders from 'slashtags-feed-reader'

const value = await feedReaders.blocks(drive)

Optionally pass a logging function:

const value = await feedReaders.blocks(drive, { log: console.log })

You can also watch whenever the drive gets an update, and reread it:

function read() {
  feedReaders.blocks(drive)
}

drive
  .ready()
  .then(read) // Read once immediatly after drive is ready
  .then(() => drive.core.on("append", read)) // Read againg every time drive is updated
  .catch(handleError);

Don't forget to close hyperdrives to avoid memory leaks

await drive.cloes()