Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
feat: migrate to next AEgir (v12)
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias authored Sep 4, 2017
1 parent 06d2e0a commit 9ffe848
Show file tree
Hide file tree
Showing 34 changed files with 277 additions and 243 deletions.
8 changes: 7 additions & 1 deletion .aegir.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict'

const factory = require('./test/ipfs-factory/tasks')

module.exports = {
karma: {
files: [{
Expand All @@ -8,5 +10,9 @@ module.exports = {
served: true,
included: false
}]
},
hooks: {
pre: factory.start,
post: factory.stop
}
}
}
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ matrix:
script:
- npm run lint
- npm run test
- npm run coverage
- make test

before_script:
- export DISPLAY=:99.0
Expand Down
4 changes: 4 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ machine:
node:
version: stable

test:
post:
- npm run coverage -- --upload

dependencies:
pre:
- google-chrome --version
Expand Down
2 changes: 1 addition & 1 deletion examples/bundle-browserify/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var ipfs = IPFS()

function store () {
var toStore = document.getElementById('source').value
ipfs.add(new Buffer(toStore), function (err, res) {
ipfs.add(Buffer.from(toStore), function (err, res) {
if (err || !res) {
return console.error('ipfs add error', err, res)
}
Expand Down
2 changes: 1 addition & 1 deletion examples/bundle-webpack/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class App extends React.Component {
protocol_version: res.protocolVersion
})
})
ipfs.add([new Buffer(stringToUse)], (err, res) => {
ipfs.add([Buffer.from(stringToUse)], (err, res) => {
if (err) throw err
const hash = res[0].hash
this.setState({added_file_hash: hash})
Expand Down
2 changes: 1 addition & 1 deletion examples/files-api/files-api.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

var ipfs = require('../../src')('localhost', 5001)
const ipfs = require('../../src')('localhost', 5001)

ipfs.files.ls('/folder1', function (err, res) {
if (err) {
Expand Down
2 changes: 1 addition & 1 deletion examples/name-api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const addAndPublish = (e) => {
e.preventDefault()

let input = e.target.elements['text']
let buffer = new Buffer(input.value)
let buffer = Buffer.from(input.value)

showStatus('adding to IPFS...', COLORS.active)

Expand Down
22 changes: 11 additions & 11 deletions examples/upload-file-via-browser/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ class App extends React.Component {
let ipfsId
const buffer = Buffer.from(reader.result)
this.ipfsApi.add(buffer)
.then((response) => {
console.log(response)
ipfsId = response[0].hash
console.log(ipfsId)
this.setState({added_file_hash: ipfsId})
}).catch((err) => {
console.error(err)
})
.then((response) => {
console.log(response)
ipfsId = response[0].hash
console.log(ipfsId)
this.setState({added_file_hash: ipfsId})
}).catch((err) => {
console.error(err)
})
}

arrayBufferToString (arrayBuffer) {
Expand All @@ -51,11 +51,11 @@ class App extends React.Component {
render () {
return (
<div>
<form id="captureMedia" onSubmit={this.handleSubmit}>
<input type="file" onChange={this.captureFile} />
<form id='captureMedia' onSubmit={this.handleSubmit}>
<input type='file' onChange={this.captureFile} />
</form>
<div>
<a target="_blank"
<a target='_blank'
href={'https://ipfs.io/ipfs/' + this.state.added_file_hash}>
{this.state.added_file_hash}
</a>
Expand Down
12 changes: 0 additions & 12 deletions gulpfile.js

This file was deleted.

34 changes: 17 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
"http": "stream-http"
},
"scripts": {
"test": "gulp test",
"test:node": "gulp test:node",
"test:browser": "gulp test:browser",
"lint": "aegir-lint",
"build": "gulp build",
"release": "gulp release",
"release-minor": "gulp release --type minor",
"release-major": "gulp release --type major",
"coverage": "gulp coverage",
"coverage-publish": "aegir-coverage publish"
"test": "aegir test --no-parallel",
"test:node": "aegir test --target node --no-parallel",
"test:browser": "aegir test --target browser",
"lint": "aegir lint",
"build": "aegir build",
"release": "aegir release --no-parallel",
"release-minor": "aegir release --type minor --no-parallel",
"release-major": "aegir release --type major --no-parallel",
"coverage": "aegir coverage --no-parallel --timeout 100000",
"coverage-publish": "aegir coverage --provider coveralls --no-parallel --timeout 100000"
},
"dependencies": {
"async": "^2.5.0",
Expand All @@ -36,13 +36,13 @@
"is-ipfs": "^0.3.0",
"is-stream": "^1.1.0",
"lru-cache": "^4.1.1",
"multiaddr": "^2.3.0",
"multiaddr": "^3.0.0",
"multihashes": "~0.4.9",
"multipart-stream": "^2.0.1",
"ndjson": "^1.5.0",
"once": "^1.4.0",
"peer-id": "~0.9.0",
"peer-info": "~0.10.0",
"peer-id": "~0.10.0",
"peer-info": "~0.11.0",
"promisify-es6": "^1.0.3",
"pump": "^1.0.2",
"qs": "^6.5.0",
Expand All @@ -52,21 +52,21 @@
"tar-stream": "^1.5.4"
},
"engines": {
"node": ">=4.0.0",
"node": ">=6.0.0",
"npm": ">=3.0.0"
},
"repository": {
"type": "git",
"url": "https://github.com/ipfs/js-ipfs-api"
},
"devDependencies": {
"aegir": "^11.0.2",
"aegir": "^12.0.2",
"chai": "^4.1.2",
"dirty-chai": "^2.0.1",
"eslint-plugin-react": "^7.3.0",
"gulp": "^3.9.1",
"hapi": "^16.5.2",
"interface-ipfs-core": "~0.31.16",
"interface-ipfs-core": "~0.31.18",
"ipfsd-ctl": "~0.22.0",
"pre-commit": "^1.2.2",
"socket.io": "^2.0.3",
Expand Down Expand Up @@ -136,4 +136,4 @@
"url": "https://github.com/ipfs/js-ipfs-api/issues"
},
"homepage": "https://github.com/ipfs/js-ipfs-api"
}
}
2 changes: 1 addition & 1 deletion src/config/replace.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const promisify = require('promisify-es6')
module.exports = (send) => {
return promisify((config, callback) => {
if (typeof config === 'object') {
config = streamifier.createReadStream(new Buffer(JSON.stringify(config)))
config = streamifier.createReadStream(Buffer.from(JSON.stringify(config)))
}

send({
Expand Down
2 changes: 1 addition & 1 deletion src/object/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ module.exports = (send) => {
}

const links = result.Links.map((l) => {
return new DAGLink(l.Name, l.Size, new Buffer(bs58.decode(l.Hash)))
return new DAGLink(l.Name, l.Size, Buffer.from(bs58.decode(l.Hash)))
})

DAGNode.create(result.Data, links, (err, node) => {
Expand Down
2 changes: 1 addition & 1 deletion src/object/links.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ module.exports = (send) => {

if (result.Links) {
links = result.Links.map((l) => {
return new DAGLink(l.Name, l.Size, new Buffer(bs58.decode(l.Hash)))
return new DAGLink(l.Name, l.Size, Buffer.from(bs58.decode(l.Hash)))
})
}
callback(null, links)
Expand Down
2 changes: 1 addition & 1 deletion src/object/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module.exports = (send) => {
}
data = (new Unixfs('directory')).marshal()
} else {
data = new Buffer(0)
data = Buffer.alloc(0)
}

DAGNode.create(data, (err, node) => {
Expand Down
4 changes: 2 additions & 2 deletions src/object/put.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ module.exports = (send) => {
if (Buffer.isBuffer(obj) && options.enc) {
buf = obj
} else {
buf = new Buffer(JSON.stringify(tmpObj))
buf = Buffer.from(JSON.stringify(tmpObj))
}
const enc = options.enc || 'json'

Expand Down Expand Up @@ -87,7 +87,7 @@ module.exports = (send) => {
})
return
} else {
DAGNode.create(new Buffer(obj.Data), obj.Links, (err, _node) => {
DAGNode.create(Buffer.from(obj.Data), obj.Links, (err, _node) => {
if (err) {
return callback(err)
}
Expand Down
42 changes: 20 additions & 22 deletions src/utils/get-dagnode.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,40 +14,38 @@ module.exports = function (send, hash, callback) {
// Retrieve the object and its data in parallel, then produce a DAGNode
// instance using this information.
parallel([
function get (done) {
(done) => {
send({
path: 'object/get',
args: multihash
}, done)
},

function data (done) {
(done) => {
// WORKAROUND: request the object's data separately, since raw bits in JSON
// are interpreted as UTF-8 and corrupt the data.
// See https://github.com/ipfs/go-ipfs/issues/1582 for more details.
send({
path: 'object/data',
args: multihash
}, done)
}],

function done (err, res) {
if (err) {
return callback(err)
}
}
], (err, res) => {
if (err) {
return callback(err)
}

var object = res[0]
var stream = res[1]
var object = res[0]
var stream = res[1]

if (Buffer.isBuffer(stream)) {
DAGNode.create(stream, object.Links, callback)
} else {
streamToValue(stream, (err, data) => {
if (err) {
return callback(err)
}
DAGNode.create(data, object.Links, callback)
})
}
})
if (Buffer.isBuffer(stream)) {
DAGNode.create(stream, object.Links, callback)
} else {
streamToValue(stream, (err, data) => {
if (err) {
return callback(err)
}
DAGNode.create(data, object.Links, callback)
})
}
})
}
6 changes: 3 additions & 3 deletions src/utils/get-files-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ function headers (file) {

function strip (name, base) {
const smallBase = base
.split('/')
.slice(0, -1)
.join('/') + '/'
.split('/')
.slice(0, -1)
.join('/') + '/'
return name.replace(smallBase, '')
}

Expand Down
6 changes: 3 additions & 3 deletions src/utils/pubsub-message-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ function deserializeFromBase64 (obj) {
}

return {
from: bs58.encode(new Buffer(obj.from, 'base64')).toString(),
seqno: new Buffer(obj.seqno, 'base64'),
data: new Buffer(obj.data, 'base64'),
from: bs58.encode(Buffer.from(obj.from, 'base64')).toString(),
seqno: Buffer.from(obj.seqno, 'base64'),
data: Buffer.from(obj.data, 'base64'),
topicCIDs: obj.topicIDs || obj.topicCIDs
}
}
Expand Down
5 changes: 3 additions & 2 deletions test/bitswap.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ const expect = chai.expect
chai.use(dirtyChai)
const FactoryClient = require('./ipfs-factory/client')

describe('.bitswap', () => {
describe('.bitswap', function () {
this.timeout(20 * 1000) // slow CI
let ipfs
let fc

before(function (done) {
before((done) => {
this.timeout(20 * 1000) // slow CI
fc = new FactoryClient()
fc.spawnNode((err, node) => {
Expand Down
15 changes: 10 additions & 5 deletions test/bootstrap.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ const FactoryClient = require('./ipfs-factory/client')
const invalidArg = 'this/Is/So/Invalid/'
const validIp4 = '/ip4/104.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z'

describe('.bootstrap', () => {
describe('.bootstrap', function () {
this.timeout(100 * 1000)

let ipfs
let fc

before(function (done) {
this.timeout(20 * 1000) // slow CI
before((done) => {
fc = new FactoryClient()
fc.spawnNode((err, node) => {
expect(err).to.not.exist()
Expand All @@ -31,7 +32,9 @@ describe('.bootstrap', () => {

let peers

describe('Callback API', () => {
describe('Callback API', function () {
this.timeout(100 * 1000)

describe('.add', () => {
it('returns an error when called with an invalid arg', (done) => {
ipfs.bootstrap.add(invalidArg, (err) => {
Expand Down Expand Up @@ -112,7 +115,9 @@ describe('.bootstrap', () => {
})
})

describe('Promise API', () => {
describe('Promise API', function () {
this.timeout(100 * 1000)

describe('.add', () => {
it('returns an error when called without args or options', () => {
return ipfs.bootstrap.add(null)
Expand Down
Loading

0 comments on commit 9ffe848

Please sign in to comment.