git ssb

2+

cel / scuttlebot.io



Tree: 254c89b83aef67583e5b1b6f6cd5fdba4fb0b493

Files: 254c89b83aef67583e5b1b6f6cd5fdba4fb0b493 / tmpl / docs / basics / read-a-file.html.js

1782 bytesRaw
1var page = require('../../page.part')
2var com = require('../../com.part')
3
4module.exports = () => page({
5 section: 'docs',
6 tab: 'docs-basics',
7 path :'/docs/basics/read-a-file.html',
8 content: `
9 <p>
10 When Scuttlebot finds the hash-ID of a file in a message, it will request its contents from the network.
11 You can then read the file from the blobstore.
12 </p>
13
14 <h2>Wait for the file to arrive</h2>
15 ${ com.code({ js: jsSnippet1, bash: bashSnippet1 }) }
16
17 <h2>Read a file to memory</h2>
18 ${ com.code({ js: jsSnippet2, bash: bashSnippet2 }) }
19
20 <h2>Read a file to disk</h2>
21 ${ com.code({ js: jsSnippet3, bash: bashSnippet3 }) }
22
23 <p class="next"><a href="/docs/basics/encryption.html">Encryption</a></p>
24 <ul class="see-also">
25 <li><a href="/modules/scuttlebot-blobs.html">Scuttlebot.Blobs API</a></li>
26 <li><a href="/advanced/linking-messages.html">Linking messages</a></li>
27 <li><a href="/advanced/pull-streams.html">Pull streams</a></li>
28 </ul>
29 `
30})
31
32var jsSnippet1 = `
33// want will not cb() until the file arrives
34sbot.blobs.want(hash, function (err) {
35 // ready to read
36})
37`
38
39var bashSnippet1 = `
40$ sbot blobs.want "&hT/5N2Kgbdv3...XYCA=.sha256"
41`
42
43var jsSnippet2 = `
44var pull = require('pull-stream')
45pull(
46 sbot.blobs.get(hash),
47 pull.collect(function (err, values) {
48 // eg values.join('') == 'hello, world'
49 })
50)
51`
52
53var bashSnippet2 = `
54$ sbot blobs.get "&hT/5N2Kgbdv3...XYCA=.sha256"
55hello, world
56`
57
58var jsSnippet3 = `
59var fs = require('fs')
60var pull = require('pull-stream')
61var toPull = require('stream-to-pull-stream')
62pull(
63 sbot.blobs.get(hash),
64 toPull.sink(fs.createWriteStream('./hello.txt'), cb)
65)
66`
67
68var bashSnippet3 = `
69$ sbot blobs.get "&hT/5N2Kgbdv3...XYCA=.sha256" > ./hello.txt
70`

Built with git-ssb-web