git ssb

2+

cel / scuttlebot.io



Tree: 2b3708ff390cc334653a3a9ff0f511f866423af7

Files: 2b3708ff390cc334653a3a9ff0f511f866423af7 / 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