ssbc / docs

Documentation repo
https://ssbc.github.io/docs
61 stars 15 forks source link

incorrect documentation: adding a blob #15

Closed dominictarr closed 5 years ago

dominictarr commented 8 years ago

@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.

dominictarr commented 8 years ago

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.

pfrazee commented 8 years ago

Ok. What about using duplex streams?

dominictarr commented 8 years ago

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.

pfrazee commented 8 years ago

That sounds good to me

dominictarr commented 8 years ago

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.

dominictarr commented 8 years ago

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

pfrazee commented 8 years ago

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

dominictarr commented 8 years ago

That was what I was thinking.

pfrazee commented 8 years ago

:+1:

NHQ commented 8 years ago

:man_with_gua_pi_mao:

stale[bot] commented 5 years ago

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.