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

Commit ecccc92

Browse files
committedDec 18, 2015
Parse chunked responses using ndjson.
Fixes #135
1 parent 7bf5460 commit ecccc92

File tree

2 files changed

+5
-13
lines changed

2 files changed

+5
-13
lines changed
 

‎src/request-api.js

+5-8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const Wreck = require('wreck')
44
const Qs = require('qs')
5+
const ndjson = require('ndjson')
56
const getFilesStream = require('./get-files-stream')
67

78
const isNode = !global.window
@@ -10,14 +11,10 @@ const isNode = !global.window
1011

1112
function parseChunkedJson (res, cb) {
1213
const parsed = []
13-
res.on('data', chunk => {
14-
try {
15-
parsed.push(JSON.parse(chunk))
16-
} catch (err) {
17-
// Browser quirks emit more than needed sometimes
18-
}
19-
})
20-
res.on('end', () => cb(null, parsed))
14+
res
15+
.pipe(ndjson.parse())
16+
.on('data', parsed.push.bind(parsed))
17+
.on('end', () => cb(null, parsed))
2118
}
2219

2320
function onRes (buffer, cb) {

‎test/api/ping.spec.js

-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22

33
describe('.ping', () => {
44
it('ping another peer', done => {
5-
// TODO remove this when https://github.com/ipfs/js-ipfs-api/issues/135 is resolved
6-
if (!isNode) {
7-
return done()
8-
}
9-
105
apiClients['b'].id((err, id) => {
116
expect(err).to.not.exist
127

0 commit comments

Comments
 (0)
This repository has been archived.