aboutsummaryrefslogtreecommitdiffstats
path: root/proposals
diff options
context:
space:
mode:
authorPaul Frazee <pfrazee@gmail.com>2018-06-27 11:30:34 -0500
committerPaul Frazee <pfrazee@gmail.com>2018-06-27 11:30:34 -0500
commit913a0b6663902e6c92bb82ae968040f11bcf5b22 (patch)
treec94703dcdbcfe5b1045a8830105d3a2e0ca8b52f /proposals
parent96db1ff0778ea8880bfc6e1981e5c18a0cf2f495 (diff)
downloaddat-deps-913a0b6663902e6c92bb82ae968040f11bcf5b22.tar.gz
dat-deps-913a0b6663902e6c92bb82ae968040f11bcf5b22.zip
Use more generic pseudo-code
Diffstat (limited to 'proposals')
-rw-r--r--proposals/0000-hypercore-header.md47
1 files changed, 23 insertions, 24 deletions
diff --git a/proposals/0000-hypercore-header.md b/proposals/0000-hypercore-header.md
index 6718c46..3b44f65 100644
--- a/proposals/0000-hypercore-header.md
+++ b/proposals/0000-hypercore-header.md
@@ -34,30 +34,29 @@ The "header" is the first entry in a hypercore. It includes a `type` and an opti
A program that is reading a hypercore will examine the `type` to determine how to process the hypercore.
-```js
-function loadCorrectStructure (hypercore, cb) {
- readHeader(hypercore, (err, header) => {
- if (err) return cb(err)
-
- if (!header) {
- // no header present - treat as a hypercore
- return cb(null, hypercore)
- }
-
- switch (header.type) {
- case 'hyperdrive':
- return cb(null, createHyperdriveV1(hypercore, header))
- case 'hyperdrive-v2':
- return cb(null, createHyperdriveV2(hypercore, header))
- case 'hyperdb':
- return cb(null, createHyperdbV1(hypercore, header))
- case '':
- return cb(null, hypercore) // no structure, treat as a hypercore
- // ...
- default:
- return cb(new Error('Unsupported: ' + header.type))
- }
- })
+```
+function loadCorrectStructure (hypercore) {
+
+ var header = parseHypercoreHeader(hypercore.readEntry(0))
+
+ if (!header) {
+ // no header present - treat as a hypercore
+ return hypercore
+ }
+
+ switch (header.type) {
+ case 'hyperdrive':
+ return new HyperdriveV1(hypercore, header)
+ case 'hyperdrive-v2':
+ return new HyperdriveV2(hypercore, header)
+ case 'hyperdb':
+ return new HyperdbV1(hypercore, header)
+ // ...
+ default:
+ // unknown type - treat as a hypercore
+ return hypercore
+ }
+
}
```