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

Commit

Permalink
feat: expose mfs files.read*Stream methods (#823)
Browse files Browse the repository at this point in the history
* feat: compatible with go-ipfs 0.4.16

* chore: update to use go0.4.17

* feat: expose mfs files.read*Stream methods

* chore: update interface-ipfs-core dependency

License: MIT
Signed-off-by: Alan Shaw <[email protected]>

* chore: increase timeouts for urlAdd tests

License: MIT
Signed-off-by: Alan Shaw <[email protected]>
  • Loading branch information
achingbrain authored and alanshaw committed Aug 2, 2018
1 parent 8536ee4 commit 70c9df1
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 14 deletions.
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
"ipfs-block": "~0.7.1",
"ipfs-unixfs": "~0.1.15",
"ipld-dag-cbor": "~0.12.1",
"ipld-dag-pb": "~0.14.5",
"is-ipfs": "~0.3.2",
"ipld-dag-pb": "~0.14.6",
"is-ipfs": "~0.4.2",
"is-pull-stream": "0.0.0",
"is-stream": "^1.1.0",
"libp2p-crypto": "~0.13.0",
Expand Down Expand Up @@ -72,16 +72,16 @@
"url": "https://github.com/ipfs/js-ipfs-api"
},
"devDependencies": {
"aegir": "^15.0.0",
"aegir": "^15.1.0",
"browser-process-platform": "~0.1.1",
"chai": "^4.1.2",
"cross-env": "^5.2.0",
"dirty-chai": "^2.0.1",
"eslint-plugin-react": "^7.10.0",
"go-ipfs-dep": "~0.4.16",
"go-ipfs-dep": "~0.4.17",
"gulp": "^3.9.1",
"interface-ipfs-core": "~0.72.1",
"ipfsd-ctl": "~0.38.0",
"interface-ipfs-core": "~0.73.0",
"ipfsd-ctl": "~0.39.0",
"pull-stream": "^3.6.8",
"socket.io": "^2.1.1",
"socket.io-client": "^2.1.1",
Expand Down
2 changes: 2 additions & 0 deletions src/files/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ module.exports = (arg) => {
rm: require('./rm')(send),
ls: require('./ls')(send),
read: require('./read')(send),
readReadableStream: require('./read-readable-stream')(send),
readPullStream: require('./read-pull-stream')(send),
write: require('./write')(send),
mv: require('./mv')(send)
}
Expand Down
26 changes: 26 additions & 0 deletions src/files/read-pull-stream.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict'

const toPull = require('stream-to-pull-stream')
const deferred = require('pull-defer')

module.exports = (send) => {
return (args, opts) => {
opts = opts || {}

const p = deferred.source()

send({
path: 'files/read',
args: args,
qs: opts
}, (err, stream) => {
if (err) {
return p.abort(err)
}

p.resolve(toPull(stream))
})

return p
}
}
26 changes: 26 additions & 0 deletions src/files/read-readable-stream.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict'

const Stream = require('readable-stream')
const pump = require('pump')

module.exports = (send) => {
return (args, opts) => {
opts = opts || {}

const pt = new Stream.PassThrough()

send({
path: 'files/read',
args: args,
qs: opts
}, (err, stream) => {
if (err) {
return pt.destroy(err)
}

pump(stream, pt)
})

return pt
}
}
18 changes: 10 additions & 8 deletions test/util.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ describe('.util', () => {

describe('.urlAdd', () => {
it('http', function (done) {
this.timeout(20 * 1000)
this.timeout(40 * 1000)

ipfs.util.addFromURL('http://example.com/', (err, result) => {
expect(err).to.not.exist()
Expand All @@ -124,7 +124,7 @@ describe('.util', () => {
})

it('https', function (done) {
this.timeout(20 * 1000)
this.timeout(40 * 1000)

ipfs.util.addFromURL('https://example.com/', (err, result) => {
expect(err).to.not.exist()
Expand All @@ -134,7 +134,7 @@ describe('.util', () => {
})

it('http with redirection', function (done) {
this.timeout(20 * 1000)
this.timeout(40 * 1000)

ipfs.util.addFromURL('http://covers.openlibrary.org/book/id/969165.jpg', (err, result) => {
expect(err).to.not.exist()
Expand All @@ -143,8 +143,8 @@ describe('.util', () => {
})
})

it('.urlAdd http with redirection', function (done) {
this.timeout(20 * 1000)
it('https with redirection', function (done) {
this.timeout(40 * 1000)

ipfs.util.addFromURL('https://coverartarchive.org/release/6e2a1694-d8b9-466a-aa33-b1077b2333c1', (err, result) => {
expect(err).to.not.exist()
Expand All @@ -161,7 +161,7 @@ describe('.util', () => {
})

it('with wrap-with-directory=true', function (done) {
this.timeout(20 * 1000)
this.timeout(40 * 1000)

ipfs.util.addFromURL('http://ipfs.io/ipfs/QmWjppACLcFLQ2qL38unKQvJBhXH3RUtcGLPk7zmrTwV61/969165.jpg?foo=bar#buzz', {
wrapWithDirectory: true
Expand All @@ -175,7 +175,9 @@ describe('.util', () => {
})
})

it('with wrap-with-directory=true and URL-escaped file name', (done) => {
it('with wrap-with-directory=true and URL-escaped file name', function (done) {
this.timeout(40 * 1000)

// Sample URL contains URL-escaped ( ) and local diacritics
ipfs.util.addFromURL('https://upload.wikimedia.org/wikipedia/commons/thumb/c/cf/Doma%C5%BElice%2C_Jir%C3%A1skova_43_%289102%29.jpg/320px-Doma%C5%BElice%2C_Jir%C3%A1skova_43_%289102%29.jpg?foo=bar#buzz', {
wrapWithDirectory: true
Expand All @@ -189,7 +191,7 @@ describe('.util', () => {
})
})

it('with invalid url', function (done) {
it('with invalid url', (done) => {
ipfs.util.addFromURL('http://invalid', (err, result) => {
expect(err.code).to.equal('ENOTFOUND')
expect(result).to.not.exist()
Expand Down

0 comments on commit 70c9df1

Please sign in to comment.