Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit c749c36

Browse files
alanshawdryajov
authored andcommitted
feat: Support specify hash algorithm in files.add (#597)
* support support specify hash alg * Add test for add with --hash option. Pass raw cid/multihash to ipfs object get/data * Allow object get/data to accept CID * Var naming tweaks from review
1 parent 2b3a577 commit c749c36

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

test/files.spec.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,25 @@ describe('.files (the MFS API part)', function () {
8787
})
8888
})
8989

90+
HASH_ALGS.forEach((name) => {
91+
it(`files.add with hash=${name} and raw-leaves=false`, (done) => {
92+
const content = String(Math.random() + Date.now())
93+
const file = {
94+
path: content + '.txt',
95+
content: Buffer.from(content)
96+
}
97+
const options = { hash: name, 'raw-leaves': false }
98+
99+
ipfs.files.add([file], options, (err, res) => {
100+
if (err) return done(err)
101+
expect(res).to.have.length(1)
102+
const cid = new CID(res[0].hash)
103+
expect(mh.decode(cid.multihash).name).to.equal(name)
104+
done()
105+
})
106+
})
107+
})
108+
90109
it.only('files.add with progress options', (done) => {
91110
ipfs.files.add(testfile, {progress: false}, (err, res) => {
92111
expect(err).to.not.exist()

0 commit comments

Comments
 (0)