This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
License: MIT Signed-off-by: achingbrain <alex@achingbrain.net>
- Loading branch information
1 parent
723bbe9
commit ccecb1b
Showing
16 changed files
with
494 additions
and
150 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict' | ||
|
||
const waterfall = require('async/waterfall') | ||
const { | ||
DAGNode | ||
} = require('ipld-dag-pb') | ||
|
||
const createNode = (ipfs, data, links, options, callback) => { | ||
waterfall([ | ||
// Create a DAGNode with the new data | ||
(cb) => DAGNode.create(data, links, cb), | ||
(newNode, cb) => { | ||
// Persist it | ||
ipfs.dag.put(newNode, { | ||
format: options.format, | ||
hashAlg: options.hashAlg | ||
}, (error) => cb(error, newNode)) | ||
} | ||
], callback) | ||
} | ||
|
||
module.exports = createNode |
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,9 @@ | ||
'use strict' | ||
|
||
const endPullStream = (callback) => { | ||
// Ugh. https://github.com/standard/standard/issues/623 | ||
const foo = true | ||
return callback(foo) | ||
} | ||
|
||
module.exports = endPullStream |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
'use strict' | ||
|
||
const waterfall = require('async/waterfall') | ||
const CID = require('cids') | ||
const log = require('debug')('mfs:utils:load-node') | ||
const bs58 = require('bs58') | ||
|
||
const loadNode = (ipfs, cid, callback) => { | ||
const multihash = cid && (cid.multihash || cid.hash) | ||
|
||
if (!multihash) { | ||
log(`No multihash passed so cannot load DAGNode`) | ||
|
||
return callback() | ||
} | ||
|
||
log(`Loading DAGNode for child ${bs58.encode(multihash)}`) | ||
|
||
waterfall([ | ||
(cb) => ipfs.dag.get(new CID(multihash), cb), | ||
(result, cb) => cb(null, result.value) | ||
], callback) | ||
} | ||
|
||
module.exports = loadNode |
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,31 @@ | ||
'use strict' | ||
|
||
// A pull stream source that will emit buffers full of zeros up to the specified length | ||
const zeros = (max = Infinity, increment = 4096) => { | ||
let i = 0 | ||
|
||
return (end, cb) => { | ||
if (end) { | ||
return cb && cb(end) | ||
} | ||
|
||
if (i >= max) { | ||
// Ugh. https://github.com/standard/standard/issues/623 | ||
const foo = true | ||
return cb(foo) | ||
} | ||
|
||
let nextLength = increment | ||
|
||
if ((i + nextLength) > max) { | ||
// final chunk doesn't divide neatly into increment | ||
nextLength = max - i | ||
} | ||
|
||
i += nextLength | ||
|
||
cb(null, Buffer.alloc(nextLength, 0)) | ||
} | ||
} | ||
|
||
module.exports = zeros |
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
Oops, something went wrong.