Files: 19a99b60a3341911535101e0c259bf16fc3e2a5a / 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