From 2f236179d76af8b13b4379a139eb7f32badb8c03 Mon Sep 17 00:00:00 2001 From: Friedel Ziegelmayer Date: Sat, 10 Dec 2016 21:33:20 +0100 Subject: [PATCH] feat(object): add template option to object.new --- API/object/README.md | 6 +++--- src/object.js | 13 +++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/API/object/README.md b/API/object/README.md index e0315695..a613730f 100644 --- a/API/object/README.md +++ b/API/object/README.md @@ -7,7 +7,9 @@ object API ##### `Go` **WIP** -##### `JavaScript` - ipfs.object.new([callback]) +##### `JavaScript` - ipfs.object.new([template][, callback]) + +`template` if defined, must be a string `unixfs-dir` and if that is passed, the created node will be an empty unixfs style directory. `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][] @@ -256,5 +258,3 @@ If no `callback` is passed, a [promise][] is returned. [DAGNode]: https://github.com/vijayee/js-ipfs-merkle-dag [multihash]: http://github.com/jbenet/multihash [promise]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise - - diff --git a/src/object.js b/src/object.js index 4468f870..cd130456 100644 --- a/src/object.js +++ b/src/object.js @@ -41,6 +41,19 @@ module.exports = (common) => { done() }) }) + + it('template unixfs-dir', (done) => { + ipfs.object.new('unixfs-dir', (err, node) => { + expect(err).to.not.exist + const nodeJSON = node.toJSON() + expect( + nodeJSON.multihash + ).to.equal( + 'QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn' + ) + done() + }) + }) }) describe('.put', () => {