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

Commit 2f29ee6

Browse files
committed
Merge pull request #103 from haadcode/master
Add object.patch to the API
2 parents 122446a + f194d3e commit 2f29ee6

File tree

2 files changed

+41
-5
lines changed

2 files changed

+41
-5
lines changed

src/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,10 @@ function IpfsAPI (host_or_multiaddr, port) {
133133
},
134134
data: argCommand('object/data'),
135135
stat: argCommand('object/stat'),
136-
links: argCommand('object/links')
136+
links: argCommand('object/links'),
137+
patch: function (file, opts, cb) {
138+
return requestAPI('object/patch', [file].concat(opts), null, null, cb)
139+
}
137140
}
138141

139142
self.swarm = {

test/tests.js

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -366,10 +366,10 @@ describe('IPFS Node.js API wrapper tests', function () {
366366
})
367367

368368
describe('.object', function () {
369-
var testObject =
370-
Buffer(JSON.stringify({Data: 'testdata', Links: []}))
371-
var testObjectHash =
372-
'QmPTkMuuL6PD8L2SwTwbcs1NPg14U8mRzerB1ZrrBrkSDD'
369+
var testObject = Buffer(JSON.stringify({Data: 'testdata', Links: []}))
370+
var testObjectHash = 'QmPTkMuuL6PD8L2SwTwbcs1NPg14U8mRzerB1ZrrBrkSDD'
371+
var testPatchObject = Buffer(JSON.stringify({Data: 'new test data'}))
372+
var testPatchObjectHash = 'QmWJDtdQWQSajQPx1UVAGWKaSGrHVWdjnrNhbooHP7LuF2'
373373

374374
it('object.put', function (done) {
375375
apiClients['a'].object.put(testObject, 'json', function (err, res) {
@@ -448,6 +448,39 @@ describe('IPFS Node.js API wrapper tests', function () {
448448
done()
449449
})
450450
})
451+
452+
it('object.patch', function (done) {
453+
this.timeout(10000)
454+
apiClients['a'].object.put(testPatchObject, 'json', function (err, res) {
455+
if (err) {
456+
throw err
457+
}
458+
apiClients['a'].object.patch(testObjectHash, ['add-link', 'next', testPatchObjectHash], function (err, res) {
459+
if (err) {
460+
throw err
461+
}
462+
var o = JSON.parse(res)
463+
assert.deepEqual(o, {
464+
Hash: 'QmZFdJ3CQsY4kkyQtjoUo8oAzsEs5BNguxBhp8sjQMpgkd',
465+
Links: null
466+
})
467+
apiClients['a'].object.get(o.Hash, function (err, res) {
468+
if (err) {
469+
throw err
470+
}
471+
assert.deepEqual(JSON.parse(res), {
472+
Data: 'testdata',
473+
Links: [{
474+
Name: 'next',
475+
Hash: 'QmWJDtdQWQSajQPx1UVAGWKaSGrHVWdjnrNhbooHP7LuF2',
476+
Size: 15
477+
}]
478+
})
479+
done()
480+
})
481+
})
482+
})
483+
})
451484
})
452485

453486
describe('.swarm', function () {

0 commit comments

Comments
 (0)