git ssb

2+

cel / scuttlebot.io



Tree: 6df421c40b28e10fe7138c1519f7c78ebb52f470

Files: 6df421c40b28e10fe7138c1519f7c78ebb52f470 / tmpl / docs / basics / publish-a-file.html.js

2441 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/publish-a-file.html',
8 content: `
9 <p>
10 To publish a file, you must first add it to Scuttlebot${"'"}s blob-store.
11 Then, you announce the file by publishing its hash-ID in a message.
12 </p>
13
14 <h2>Add a file from memory</h2>
15 ${ com.code({ js: jsSnippet1, bash: bashSnippet1 }) }
16
17 <h2>Add a file from disk</h2>
18 ${ com.code({ js: jsSnippet2, bash: bashSnippet2 }) }
19
20 <h2>Publish the file to the network</h2>
21 <p>Adding a file will only affect the local blobstore. To distribute the file, you must also link to it in an unencrypted message.</p>
22 ${ com.code({ js: jsSnippet3, bash: bashSnippet3 }) }
23
24 <p class="next"><a href="/docs/basics/read-a-file.html">Read a file</a></p>
25 <ul class="see-also">
26 <li><a href="/modules/scuttlebot-blobs.html">Scuttlebot.Blobs API</a></li>
27 <li><a href="/advanced/linking-messages.html">Linking messages</a></li>
28 <li><a href="/advanced/pull-streams.html">Pull streams</a></li>
29 </ul>
30 `
31})
32
33var jsSnippet1 = `
34var pull = require('pull-stream')
35pull(
36 pull.values('hello, world'),
37 sbot.blobs.add(function (err, hash) {
38 // 'hash' is the hash-id of the blob
39 })
40)
41`
42
43var bashSnippet1 = `
44$ echo "hello, world" | sbot blobs.add
45&hT/5N2Kgbdv3IsTr6d3WbY9j3a6pf1IcPswg2nyXYCA=.sha256
46`
47
48var jsSnippet2 = `
49var fs = require('fs')
50var pull = require('pull-stream')
51var toPull = require('stream-to-pull-stream')
52pull(
53 toPull.source(fs.createReadStream('./hello.txt')),
54 sbot.blobs.add(function (err, hash) {
55 // 'hash' is the hash-id of the blob
56 })
57)
58`
59
60var bashSnippet2 = `
61$ cat ./hello.txt | sbot blobs.add
62&hT/5N2Kgbdv3IsTr6d3WbY9j3a6pf1IcPswg2nyXYCA=.sha256
63`
64
65var jsSnippet3 = `
66sbot.publish({
67 type: 'post',
68 text: 'checkout [this file!]('+hash+')',
69 mentions: [{
70 link: hash, // the hash given by blobs.add
71 name: 'hello.txt', // optional, but recommended
72 size: 12, // optional, but recommended
73 type: 'text/plain' // optional, but recommended
74 }]
75}, function (err, msg) {
76 // ...
77})
78`
79
80var bashSnippet3 = `
81$ sbot publish --type post --text "checkout this file!" \\
82 --mentions.link "&hT/5N2Kgbdv3IsT...swg2nyXYCA=.sha256" \\
83 --mentions.name "hello.txt" \\
84 --mentions.size 12 \\
85 --mentions.type "text/plain"
86`

Built with git-ssb-web