ssbc / docs

Documentation repo

Home Page:https://ssbc.github.io/docs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

incorrect documentation: adding a blob

dominictarr opened this issue · comments

@NHQ found that adding blobs doesn't match the documentation. What we have is correct if you embed scuttlebot, but not if you use the client.

To use the current api, you need to calculate the hash yourself.

function createHash() {
  var hash = crypto.createHash('sha256'), hasher
  return hasher = pull.through(function (data) {
    hash.update(data)
  }, function () {
    hasher.digest = '&'+hash.digest('base64')+'.sha256'
  })
}
var hasher = createHash()
pull(
   toPull.source(fileStream),
   hasher,
    sbot.blobs.add(function (err) {
      hasher.digest //here is the hash.
     })
)

The better solution would be to update muxrpc to send the value in the callback in a sink stream.

Having investigated this a little further I have decided that making that change to muxrpc would introduce considerable complexification... having that change will mean that you get a write ack after a write stream - not just writing it to the connection, but writing to the remote database. That will probably turn out to be a very good idea one day... But it would also be quite a bit of work.

Ok. What about using duplex streams?

It would be simple enough to make it a duplex stream... I was thinking make a special duplex syntax where if you pass it a callback it would put the duplex data into that... and maybe error if it wrote more than one messages. A duplex stream on it's own would work, but would be more awkward.

That sounds good to me

I guess you could use it with a pull.one(function (err, data) { }) that would read a single value and error (aborting the source) if there was more than one.

we could do that without actually making any changes to muxrpc.

Can we make calls to duplexes in muxrpc do that, automatically, if a cb is given as the last param?

That was what I was thinking.

👍

commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.