This repository has been archived by the owner on Apr 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support exporting nodes encoded with the identity hash (#27)
* feat: support exporting nodes encoded with the identity hash We can encode small amounts of data inside CIDs so we should be able to export them too. * chore: update require
- Loading branch information
1 parent
d12178a
commit 4a02ee7
Showing
5 changed files
with
110 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
'use strict' | ||
|
||
const errCode = require('err-code') | ||
const extractDataFromBlock = require('../utils/extract-data-from-block') | ||
const validateOffsetAndLength = require('../utils/validate-offset-and-length') | ||
const mh = require('multihashing-async').multihash | ||
|
||
const rawContent = (node) => { | ||
return function * (options = {}) { | ||
const { | ||
offset, | ||
length | ||
} = validateOffsetAndLength(node.length, options.offset, options.length) | ||
|
||
yield extractDataFromBlock(node, 0, offset, offset + length) | ||
} | ||
} | ||
|
||
const resolve = async (cid, name, path, toResolve, resolve, depth, ipld) => { | ||
if (toResolve.length) { | ||
throw errCode(new Error(`No link named ${path} found in raw node ${cid.toBaseEncodedString()}`), 'ERR_NOT_FOUND') | ||
} | ||
|
||
const buf = await mh.decode(cid.multihash) | ||
|
||
return { | ||
entry: { | ||
name, | ||
path, | ||
cid, | ||
node: buf, | ||
content: rawContent(buf.digest), | ||
depth | ||
} | ||
} | ||
} | ||
|
||
module.exports = resolve |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters