git ssb

2+

cel / scuttlebot.io



Tree: c52c66bca2f11bf3f73ea7ec3a141a23510f6e3b

Files: c52c66bca2f11bf3f73ea7ec3a141a23510f6e3b / tmpl / docs / advanced / read-a-file.md

822 bytesRaw

When Scuttlebot finds the hash-ID of a file in a message, it will request its contents from the network. You can then read the file from the blobstore.

Wait for the file to arrive

Files always arrive after the message that first announces it. So, it's a good idea to call want, which will return when the file has arrived:

// want will not cb() until the file arrives
sbot.blobs.want(hash, function (err) {
  // ready to read
})
$ sbot blobs.want "&hT/5N2Kgbdv3...XYCA=.sha256"

Read a file

Once the file is available, you can fetch it using 'get':

var pull = require('pull-stream')
pull(
  sbot.blobs.get(hash),
  pull.collect(function (err, values) {
    // eg values.join('') == 'hello, world'
  })
)
$ sbot blobs.get "&hT/5N2Kgbdv3...XYCA=.sha256"
hello, world

Built with git-ssb-web