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

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ipfs-inactive/js-ipfs-http-client
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 8c5b07587bb6
Choose a base ref
...
head repository: ipfs-inactive/js-ipfs-http-client
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 48b0207b0655
Choose a head ref
  • 2 commits
  • 3 files changed
  • 1 contributor

Commits on Nov 21, 2015

  1. Verified

    This commit was signed with the committer’s verified signature.
    renovate-bot Mend Renovate
    Copy the full SHA
    093de9b View commit details
  2. Copy the full SHA
    48b0207 View commit details
Showing with 27 additions and 22 deletions.
  1. +1 −0 package.json
  2. +15 −10 src/request-api.js
  3. +11 −12 test/tests.js
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -52,6 +52,7 @@
"require-dir": "^0.3.0",
"rimraf": "^2.4.3",
"run-sequence": "^1.1.4",
"stream-equal": "^0.1.7",
"stream-http": "^2.0.2",
"uglify-js": "^2.4.24",
"vinyl-buffer": "^1.0.0",
25 changes: 15 additions & 10 deletions src/request-api.js
Original file line number Diff line number Diff line change
@@ -8,6 +8,18 @@ const isNode = !global.window

// -- Internal

function parseChunkedJson (res, cb) {
const parsed = []
res.on('data', chunk => {
try {
parsed.push(JSON.parse(chunk))
} catch (err) {
// Browser quirks emit more than needed sometimes
}
})
res.on('end', () => cb(null, parsed))
}

function onRes (buffer, cb) {
return (err, res) => {
if (err) {
@@ -33,16 +45,9 @@ function onRes (buffer, cb) {
if (stream && !buffer) return cb(null, res)

if (chunkedObjects) {
const parsed = []
res.on('data', chunk => {
try {
parsed.push(JSON.parse(chunk))
} catch (err) {
// Browser quirks emit more than needed sometimes
}
})
res.on('end', () => cb(null, parsed))
return
if (isJson) return parseChunkedJson(res, cb)

return Wreck.read(res, null, cb)
}

Wreck.read(res, {json: isJson}, cb)
23 changes: 11 additions & 12 deletions test/tests.js
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
/* global describe it before */

const ipfsAPI = require('../src/index.js')
const streamEqual = require('stream-equal')
const assert = require('assert')
const path = require('path')
const File = require('vinyl')
@@ -16,7 +17,7 @@ let testfileBig

if (isNode) {
testfile = require('fs').readFileSync(__dirname + '/testfile.txt')
testfileBig = require('fs').readFileSync(__dirname + '/100mb.random')
testfileBig = require('fs').createReadStream(__dirname + '/100mb.random', { bufferSize: 128 })
} else {
testfile = require('raw!./testfile.txt')
// browser goes nuts with a 100mb in memory
@@ -132,8 +133,7 @@ describe('IPFS Node.js API wrapper tests', () => {
}
this.timeout(10000)

let buf = new Buffer(testfileBig)
apiClients['a'].add(buf, (err, res) => {
apiClients['a'].add(testfileBig, (err, res) => {
if (err) throw err

// assert.equal(res.length, 1)
@@ -229,21 +229,20 @@ describe('IPFS Node.js API wrapper tests', () => {
if (!isNode) {
return done()
}
this.timeout(10000)
this.timeout(60000)

apiClients['a'].cat('Qmaw8jKK2vdd1gxiYqfyXJgVwfibiXiH3H81eVViJRXMJj', (err, res) => {
if (err) {
throw err
}

let buf = ''
res
.on('error', err => { throw err })
.on('data', data => buf += data)
.on('end', () => {
assert.equal(buf, testfileBig)
done()
})
// Do not blow out the memory of nodejs :)
streamEqual(res, testfileBig, (err, equal) => {
console.log('compare done', err, equal)
if (err) throw err
assert(equal)
done()
})
})
})
})