diff --git a/package.json b/package.json index d3d302c3..9fd19be9 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,6 @@ "dirty-chai": "^2.0.1", "es6-promisify": "^6.0.1", "hat": "0.0.3", - "into-stream": "^5.1.0", "ipfs-block": "~0.8.0", "ipfs-unixfs": "~0.1.16", "ipfs-utils": "~0.0.3", diff --git a/src/dht/provide.js b/src/dht/provide.js index 915f9f26..11fbe88f 100644 --- a/src/dht/provide.js +++ b/src/dht/provide.js @@ -60,7 +60,10 @@ module.exports = (createCommon, options) => { }) it('should allow multiple CIDs to be passed', (done) => { - ipfs.add([Buffer.from('t0'), Buffer.from('t1')], (err, res) => { + ipfs.add([ + { content: Buffer.from('t0') }, + { content: Buffer.from('t1') } + ], (err, res) => { if (err) return done(err) ipfs.dht.provide([ diff --git a/src/files-regular/add-from-stream.js b/src/files-regular/add-from-stream.js index f97a5946..96ae0938 100644 --- a/src/files-regular/add-from-stream.js +++ b/src/files-regular/add-from-stream.js @@ -1,9 +1,9 @@ /* eslint-env mocha */ 'use strict' -const loadFixture = require('aegir/fixtures') -const into = require('into-stream') +const { Readable } = require('readable-stream') const { getDescribe, getIt, expect } = require('../utils/mocha') +const { fixtures } = require('./utils') module.exports = (createCommon, options) => { const describe = getDescribe(options) @@ -33,11 +33,17 @@ module.exports = (createCommon, options) => { after((done) => common.teardown(done)) it('should add from a stream', (done) => { - const testData = loadFixture('test/fixtures/15mb.random', 'interface-ipfs-core') + const stream = new Readable({ + read () { + this.push(fixtures.bigFile.data) + this.push(null) + } + }) - ipfs.addFromStream(into(testData), (err, result) => { + ipfs.addFromStream(stream, (err, result) => { expect(err).to.not.exist() expect(result.length).to.equal(1) + expect(result[0].hash).to.equal(fixtures.bigFile.cid) done() }) }) diff --git a/src/files-regular/add.js b/src/files-regular/add.js index eb364306..4d3c34d9 100644 --- a/src/files-regular/add.js +++ b/src/files-regular/add.js @@ -4,7 +4,6 @@ const { fixtures } = require('./utils') const Readable = require('readable-stream').Readable const pull = require('pull-stream') -const path = require('path') const expectTimeout = require('../utils/expect-timeout') const { getDescribe, getIt, expect } = require('../utils/mocha') const { supportsFileReader } = require('ipfs-utils/src/supports') @@ -154,31 +153,34 @@ module.exports = (createCommon, options) => { }) }) - it('should not be able to add by path', (done) => { - const validPath = path.join(process.cwd() + '/package.json') + it('should add a string', (done) => { + const data = 'a string' + const expectedCid = 'QmQFRCwEpwQZ5aQMqCsCaFbdjNLLHoyZYDjr92v1F7HeqX' - ipfs.add(validPath, (err, res) => { - expect(err).to.exist() - done() - }) - }) - - it('should not be able to add a string', (done) => { - const data = `TEST${Date.now()}` + ipfs.add(data, (err, filesAdded) => { + expect(err).to.not.exist() - ipfs.add(data, (err) => { - expect(err).to.exist() - expect(err.message).to.contain('Input not supported') + expect(filesAdded).to.be.length(1) + const { path, size, hash } = filesAdded[0] + expect(path).to.equal(expectedCid) + expect(size).to.equal(16) + expect(hash).to.equal(expectedCid) done() }) }) - it('should not be able to add a non-Buffer TypedArray', (done) => { - const data = Uint8Array.from([Date.now()]) + it('should add a TypedArray', (done) => { + const data = Uint8Array.from([1, 3, 8]) + const expectedCid = 'QmRyUEkVCuHC8eKNNJS9BDM9jqorUvnQJK1DM81hfngFqd' - ipfs.add(data, (err) => { - expect(err).to.exist() - expect(err.message).to.contain('Input not supported') + ipfs.add(data, (err, filesAdded) => { + expect(err).to.not.exist() + + expect(filesAdded).to.be.length(1) + const { path, size, hash } = filesAdded[0] + expect(path).to.equal(expectedCid) + expect(size).to.equal(11) + expect(hash).to.equal(expectedCid) done() }) }) @@ -353,7 +355,7 @@ module.exports = (createCommon, options) => { }) it('should fail when passed invalid input', (done) => { - const nonValid = 'sfdasfasfs' + const nonValid = 138 ipfs.add(nonValid, (err, result) => { expect(err).to.exist()