git ssb

0+

cel-desktop / ssb-pkg



Commit d1a209da91481b68bc81030e13ce7326503908c8

Include sizes of blobs passed to install.js

cel committed on 5/17/2020, 9:09:46 PM
Parent: cc78d8d102860559afcb45fb453361b6545d9ae6

Files changed

lib/producer.jschanged
lib/ssb.jschanged
prelude/install.jschanged
lib/producer.jsView
@@ -23,36 +23,46 @@
2323 return str.replace(key, vars[key])
2424 }, template)
2525 }
2626
27 +function getJson(file, cb) {
28 + fs.readFile(file, 'utf8', function (err, data) {
29 + if (err) return cb(err)
30 + var obj
31 + try { obj = JSON.parse(data) }
32 + catch(e) { return cb(e) }
33 + cb(null, obj)
34 + })
35 +}
36 +
2737 function addGzBlobs(ssb, file, cb) {
28- var idFile = file + '.gzids'
29- fs.readFile(idFile, 'utf8', function (err, contents) {
30- if (!err) return cb(null, contents.trim().split('\n'))
31- if (err.code !== 'ENOENT') return cb(err)
38 + var linksFile = file + '.gzlinks'
39 + getJson(linksFile, function (err, links) {
40 + if (!err) return cb(null, links)
41 + if (err.code !== 'ENOENT' && err.message !== 'SyntaxError') return cb(err)
3242 fs.createReadStream(file)
3343 .pipe(zlib.createGzip())
34- .pipe(ssb.addBlobs(function (err, ids) {
44 + .pipe(ssb.addBlobs(function (err, links) {
3545 if (err) return cb(err)
36- fs.writeFile(idFile, ids.join('\n')+'\n', function (err) {
46 + fs.writeFile(linksFile, JSON.stringify(links, null, 2), function (err) {
3747 if (err) console.trace(err)
38- cb(null, ids)
48 + cb(null, links)
3949 })
4050 }))
4151 })
4252 }
4353
44-function caseNodeBlobs(ids, pattern) {
45- return ' ' + pattern + ') set -- \\\n ' + ids.map(function (id) {
46- return "'" + id + "'"
54 +function caseNodeBlobs(links, pattern) {
55 + return ' ' + pattern + ') set -- \\\n ' + links.map(function (link) {
56 + return "'" + link.link + "'"
4757 }).join(' \\\n ') + ';;\n'
4858 }
4959
50-function switchNodeBlobs(nodeBlobIds, targets) {
60 +function switchNodeBlobs(nodeBlobs, targets) {
5161 return Object.keys(targets).map(function (t) {
5262 var target = targets[t]
53- var ids = nodeBlobIds[target.platform + '-' + target.arch]
54- if (!ids) throw new Error('target without node blob ids: ' + t)
63 + var links = nodeBlobs[target.platform + '-' + target.arch]
64 + if (!links) throw new Error('target without node blobs: ' + t)
5565 var system =
5666 target.platform === 'linux' ? 'Linux' :
5767 target.platform === 'macos' ? 'Darwin*' :
5868 null
@@ -64,9 +74,9 @@
6474 null
6575 if (!system) throw new Error('Unknown system: ' + target.platform)
6676 if (!machine) throw new Error('Unknown machine: ' + target.arch)
6777 var pattern = system + '\\ ' + machine
68- return caseNodeBlobs(ids, pattern)
78 + return caseNodeBlobs(links, pattern)
6979 }).filter(Boolean).join('\n')
7080 }
7181
7282 export default function ({ backpack, bakes, slash, targets, fabricator, output, binName, ssb }) {
@@ -74,10 +84,10 @@
7484 if (!Buffer.alloc) {
7585 throw wasReported('Your node.js does not have Buffer.alloc. Please upgrade!');
7686 }
7787
78- var nodeBlobIds = {}
79- var preludeBlobIds, payloadBlobIds, vfsBlobIds, installJsBlobId
88 + var nodeBlobs = {}
89 + var preludeBlobs, payloadBlobs, vfsBlobs, installJsBlobId
8090 var waiting = 3
8191
8292 let { prelude, entrypoint, otherEntrypoints, stripes } = backpack;
8393 entrypoint = snapshotify(entrypoint, slash);
@@ -102,11 +112,11 @@
102112 }
103113
104114 for (const target of targets) {
105115 waiting++
106- addGzBlobs(ssb, target.binaryPath, function (err, ids) {
116 + addGzBlobs(ssb, target.binaryPath, function (err, links) {
107117 if (err) return reject(err)
108- nodeBlobIds[target.platform + '-' + target.arch] = ids
118 + nodeBlobs[target.platform + '-' + target.arch] = links
109119 if (!--waiting) next()
110120 })
111121 }
112122
@@ -165,13 +175,13 @@
165175
166176 var blobGroup = stripe.blobGroup
167177 if (blobGroup) {
168178 var readFile = fs.createReadStream(stripe.file)
169- return readFile.pipe(ssb.addBlobs(function (err, ids) {
179 + return readFile.pipe(ssb.addBlobs(function (err, links) {
170180 if (err) return cb(err)
171181 var snap = snapshotify(stripe.snap, slash);
172182 var blobs = fileBlobs[blobGroup] || (fileBlobs[blobGroup] = {})
173- blobs[snap] = ids
183 + blobs[snap] = links
174184 // vfs entry will be added during install
175185 stripe.skip = true
176186 cb(null, intoStream(Buffer.alloc(0)))
177187 }))
@@ -191,31 +201,31 @@
191201 ).on('error', (error) => {
192202 reject(error);
193203 });
194204
195- function onAddInstallJsBlobs(err, ids) {
205 + function onAddInstallJsBlobs(err, links) {
196206 if (err) return reject(err)
197- if (ids.length > 1) {
207 + if (links.length > 1) {
198208 return reject(new Error('install.js must fit in one blob'))
199209 }
200- installJsBlobId = ids
210 + installJsBlobId = links[0].link
201211 if (!--waiting) next()
202212 }
203213
204- var writable = ssb.addBlobs(function (err, ids) {
214 + var writable = ssb.addBlobs(function (err, links) {
205215 if (err) return reject(err)
206- preludeBlobIds = ids
216 + preludeBlobs = links
207217 if (!--waiting) next()
208218 })
209219 writable.write(prelude)
210220 writable.end()
211221 // pull-stream-to-stream writable doesn't support .end(data)
212222
213- function onAddPayloadBlobs(err, ids) {
223 + function onAddPayloadBlobs(err, links) {
214224 if (err) return reject(err)
215- payloadBlobIds = ids
216- var writable = ssb.addBlobs(function (err, ids) {
217- vfsBlobIds = ids
225 + payloadBlobs = links
226 + var writable = ssb.addBlobs(function (err, links) {
227 + vfsBlobs = links
218228 if (err) return reject(err)
219229 if (!--waiting) next()
220230 })
221231 writable.write(JSON.stringify(vfs))
@@ -226,13 +236,13 @@
226236 var installSh = path.join(__dirname, '../prelude/install.sh')
227237 var installScriptTemplate = fs.readFileSync(installSh, 'utf8')
228238 var settings = {
229239 '%INSTALL_JS_BLOB%': installJsBlobId,
230- '%SWITCH_NODE_BLOBS%': switchNodeBlobs(nodeBlobIds, targets),
240 + '%SWITCH_NODE_BLOBS%': switchNodeBlobs(nodeBlobs, targets),
231241 '%SETTINGS%': JSON.stringify({
232- preludeBlobs: preludeBlobIds,
233- payloadBlobs: payloadBlobIds,
234- vfsBlobs: vfsBlobIds,
242 + preludeBlobs: preludeBlobs,
243 + payloadBlobs: payloadBlobs,
244 + vfsBlobs: vfsBlobs,
235245 binName: binName,
236246 entrypoint: entrypoint,
237247 otherEntrypoints: otherEntrypoints,
238248 bakes: bakes,
lib/ssb.jsView
@@ -18,21 +18,19 @@
1818
1919 addBlob(data, cb) {
2020 pull(
2121 pull.once(data),
22- this.sbot.blobs.add(cb)
22 + this.sbot.blobs.add((err, id) => {
23 + if (err) return cb(err)
24 + cb(null, {link: id, size: data.length})
25 + })
2326 )
2427 }
2528
2629 addBlobs(cb) {
2730 return toStream(pull(
2831 Block({size: 5242879, zeroPadding: false}),
29- pull.asyncMap((buf, cb) => {
30- pull(
31- pull.once(buf),
32- this.sbot.blobs.add(cb)
33- )
34- }),
32 + pull.asyncMap(this.addBlob.bind(this)),
3533 pull.collect(cb)
3634 ))
3735 }
3836
prelude/install.jsView
@@ -7,12 +7,12 @@
77 var STORE_CONTENT = 1
88
99 var settings = JSON.parse(fs.readFileSync(3))
1010
11-function ReadBlobs(ids) {
12- if (!Array.isArray(ids)) throw new TypeError('blob ids should be array')
13- this.ids = ids
14- stream.Readable.call(this, ids)
11 +function ReadBlobs(links) {
12 + if (!Array.isArray(links)) throw new TypeError('blob links should be array')
13 + this.links = links
14 + stream.Readable.call(this, links)
1515 }
1616 ReadBlobs.prototype = new stream.Readable()
1717 ReadBlobs.prototype.constructor = ReadBlobs
1818 ReadBlobs.prototype.i = 0
@@ -27,10 +27,11 @@
2727 if (this.res) this.res.destroy(), this.res = null
2828 cb(err)
2929 }
3030 ReadBlobs.prototype._makeReq = function () {
31- if (this.i >= this.ids.length) return this.push(null)
32- var id = this.ids[this.i++]
31 + if (this.i >= this.links.length) return this.push(null)
32 + var link = this.links[this.i++]
33 + var id = typeof link === 'string' ? link : link && link.link
3334 var url = this.blobsBase + id
3435 console.error(id)
3536 var onResp = (res) => {
3637 this.res = res

Built with git-ssb-web