git ssb

2+

cel / scuttlebot.io



Tree: 3eba1cf8620514db3af2369ef361956125b8f0b6

Files: 3eba1cf8620514db3af2369ef361956125b8f0b6 / 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