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

Commit 2f23617

Browse files
feat(object): add template option to object.new
1 parent a43b71b commit 2f23617

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

API/object/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ object API
77
88
##### `Go` **WIP**
99

10-
##### `JavaScript` - ipfs.object.new([callback])
10+
##### `JavaScript` - ipfs.object.new([template][, callback])
11+
12+
`template` if defined, must be a string `unixfs-dir` and if that is passed, the created node will be an empty unixfs style directory.
1113

1214
`callback` must follow `function (err, node) {}` signature, where `err` is an error if the operation was not successful and `node` is a MerkleDAG node of the type [DAGNode][]
1315

@@ -256,5 +258,3 @@ If no `callback` is passed, a [promise][] is returned.
256258
[DAGNode]: https://github.com/vijayee/js-ipfs-merkle-dag
257259
[multihash]: http://github.com/jbenet/multihash
258260
[promise]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
259-
260-

src/object.js

+13
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,19 @@ module.exports = (common) => {
4141
done()
4242
})
4343
})
44+
45+
it('template unixfs-dir', (done) => {
46+
ipfs.object.new('unixfs-dir', (err, node) => {
47+
expect(err).to.not.exist
48+
const nodeJSON = node.toJSON()
49+
expect(
50+
nodeJSON.multihash
51+
).to.equal(
52+
'QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn'
53+
)
54+
done()
55+
})
56+
})
4457
})
4558

4659
describe('.put', () => {

0 commit comments

Comments
 (0)