From 9b7e71e417d399ae24019dfb2b2493b82329211c Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Fri, 20 Nov 2015 20:59:35 +0100 Subject: [PATCH] feat: Fix log/tail for 0.3.9 --- package.json | 1 + src/index.js | 6 +++++- test/tests.js | 13 ++++++++----- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index d6635b8f0e..cc65733417 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "merge-stream": "^1.0.0", "multiaddr": "^1.0.0", "multipart-stream": "^2.0.0", + "ndjson": "^1.4.3", "qs": "^6.0.0", "vinyl": "^1.1.0", "vinyl-fs-browser": "^2.1.1-1", diff --git a/src/index.js b/src/index.js index b2867a1de3..f13ed9efd7 100644 --- a/src/index.js +++ b/src/index.js @@ -4,6 +4,7 @@ const multiaddr = require('multiaddr') const getConfig = require('./config') const getRequestAPI = require('./request-api') const Wreck = require('wreck') +const ndjson = require('ndjson') exports = module.exports = IpfsAPI @@ -203,7 +204,10 @@ function IpfsAPI (host_or_multiaddr, port) { self.log = { tail (cb) { - return requestAPI('log/tail', null, {enc: 'text'}, null, true, cb) + requestAPI('log/tail', null, {}, null, false, (err, res) => { + if (err) return cb(err) + cb(null, res.pipe(ndjson.parse())) + }) } } diff --git a/test/tests.js b/test/tests.js index 75af955ff6..ee3038202f 100644 --- a/test/tests.js +++ b/test/tests.js @@ -619,15 +619,18 @@ describe('IPFS Node.js API wrapper tests', () => { }) describe('.log', function () { - // TODO news 0.3.9 ndjson stuff - it.skip('.log.tail', function (done) { + it('.log.tail', function (done) { + this.timeout(10000) + apiClients['a'].log.tail((err, res) => { if (err) { throw err } - - console.log('->', res) - done() + res.once('data', obj => { + assert(obj) + assert.equal(typeof obj, 'object') + done() + }) }) }) })