diff options
author | Paul Frazee <pfrazee@gmail.com> | 2018-06-27 11:30:34 -0500 |
---|---|---|
committer | Paul Frazee <pfrazee@gmail.com> | 2018-06-27 11:30:34 -0500 |
commit | 913a0b6663902e6c92bb82ae968040f11bcf5b22 (patch) | |
tree | c94703dcdbcfe5b1045a8830105d3a2e0ca8b52f /proposals | |
parent | 96db1ff0778ea8880bfc6e1981e5c18a0cf2f495 (diff) | |
download | dat-deps-913a0b6663902e6c92bb82ae968040f11bcf5b22.tar.gz dat-deps-913a0b6663902e6c92bb82ae968040f11bcf5b22.zip |
Use more generic pseudo-code
Diffstat (limited to 'proposals')
-rw-r--r-- | proposals/0000-hypercore-header.md | 47 |
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 + } + } ``` |