This repository has been archived by the owner on Mar 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
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 <[email protected]>
- Loading branch information
1 parent
b2fbd5d
commit 9302f01
Showing
9 changed files
with
287 additions
and
186 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,31 @@ | ||
'use strict' | ||
|
||
const pull = require('pull-stream/pull') | ||
const values = require('pull-stream/sources/values') | ||
const collect = require('pull-stream/sinks/collect') | ||
const importer = require('ipfs-unixfs-importer') | ||
const CID = require('cids') | ||
|
||
const createShard = (mfs, files, shardSplitThreshold = 10) => { | ||
return new Promise((resolve, reject) => { | ||
pull( | ||
values(files), | ||
importer(mfs.ipld, { | ||
shardSplitThreshold, | ||
reduceSingleLeafToSelf: false, // same as go-ipfs-mfs implementation, differs from `ipfs add`(!) | ||
leafType: 'raw' // same as go-ipfs-mfs implementation, differs from `ipfs add`(!) | ||
}), | ||
collect((err, files) => { | ||
if (err) { | ||
return reject(files) | ||
} | ||
|
||
const dir = files[files.length - 1] | ||
|
||
resolve(new CID(dir.multihash)) | ||
}) | ||
) | ||
}) | ||
} | ||
|
||
module.exports = createShard |
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.