Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,15 @@ $ ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods "[\"PUT\", \"P
- [`ipfs.files.getPullStream(ipfsPath, [options])`](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/FILES.md#getpullstream)
- `ipfs.ls`
- MFS (mutable file system) specific:
- `ipfs.files.cp`
- `ipfs.files.ls`
- `ipfs.files.mkdir`
- `ipfs.files.stat`
- `ipfs.files.rm`
- `ipfs.files.read`
- `ipfs.files.write`
- `ipfs.files.mv`
- `ipfs.files.flush(path, [callback])`
- [`ipfs.files.cp([from, to], [callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/FILES.md#cp)
- [`ipfs.files.mkdir(path, [options, callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/FILES.md#mkdir)
- [`ipfs.files.stat(path, [options, callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/FILES.md#stat)
- [`ipfs.files.rm(path, [options, callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/FILES.md#rm)
- [`ipfs.files.read(path, [options, callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/FILES.md#read)
- [`ipfs.files.write(path, content, [options, callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/FILES.md#write)
- [`ipfs.files.mv([from, to], [callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/FILES.md#mv)
- [`ipfs.files.ls([path, options, callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/FILES.md#ls)
- [`ipfs.files.flush([path, callback])`(https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/FILES.md#flush)

- [block](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/BLOCK.md)
- [`ipfs.block.get(cid, [options, callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/BLOCK.md#get)
Expand Down
5 changes: 5 additions & 0 deletions src/files/flush.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ const promisify = require('promisify-es6')

module.exports = (send) => {
return promisify((args, callback) => {
if (typeof args === 'function') {
callback = args
args = '/'
}

return send({
path: 'files/flush',
args: args
Expand Down
6 changes: 4 additions & 2 deletions src/files/read.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
'use strict'

const promisify = require('promisify-es6')
const streamToValue = require('../utils/stream-to-value')

module.exports = (send) => {
return promisify((args, opts, callback) => {
if (typeof (opts) === 'function') {
callback = opts
opts = {}
}
send({

send.andTransform({
path: 'files/read',
args: args,
qs: opts
}, callback)
}, streamToValue, callback)
})
}
96 changes: 18 additions & 78 deletions test/files.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,19 +244,10 @@ describe('.files (the MFS API part)', function () {
.write('/test-folder/test-file-2.txt', Buffer.from('hello world'), {create: true}, (err) => {
expect(err).to.not.exist()

ipfs.files.read('/test-folder/test-file-2.txt', (err, stream) => {
ipfs.files.read('/test-folder/test-file-2.txt', (err, buf) => {
expect(err).to.not.exist()

let buf = ''
stream
.on('error', (err) => expect(err).to.not.exist())
.on('data', (data) => {
buf += data
})
.on('end', () => {
expect(buf).to.be.equal('hello world')
done()
})
expect(buf.toString()).to.be.equal('hello world')
done()
})
})
})
Expand All @@ -266,21 +257,10 @@ describe('.files (the MFS API part)', function () {
.write('/test-folder/test-file-2.txt', Buffer.from('hello world'), (err) => {
expect(err).to.not.exist()

ipfs.files.read('/test-folder/test-file-2.txt', (err, stream) => {
ipfs.files.read('/test-folder/test-file-2.txt', (err, buf) => {
expect(err).to.not.exist()

let buf = ''
stream
.on('error', (err) => {
expect(err).to.not.exist()
})
.on('data', (data) => {
buf += data
})
.on('end', () => {
expect(buf).to.be.equal('hello world')
done()
})
expect(buf.toString()).to.be.equal('hello world')
done()
})
})
})
Expand Down Expand Up @@ -315,20 +295,10 @@ describe('.files (the MFS API part)', function () {
return done()
}

ipfs.files.read('/test-folder/test-file', (err, stream) => {
ipfs.files.read('/test-folder/test-file', (err, buf) => {
expect(err).to.not.exist()
let buf = ''
stream
.on('error', (err) => {
expect(err).to.not.exist()
})
.on('data', (data) => {
buf += data
})
.on('end', () => {
expect(Buffer.from(buf)).to.deep.equal(testfile)
done()
})
expect(Buffer.from(buf)).to.deep.equal(testfile)
done()
})
})

Expand Down Expand Up @@ -417,19 +387,9 @@ describe('.files (the MFS API part)', function () {
.then(() => {
return ipfs.files.read('/test-folder/test-file-2.txt')
})
.then((stream) => {
let buf = ''
stream
.on('error', (err) => {
expect(err).to.not.exist()
})
.on('data', (data) => {
buf += data
})
.on('end', () => {
expect(buf).to.be.equal('hello world')
done()
})
.then((buf) => {
expect(buf.toString()).to.be.equal('hello world')
done()
})
.catch(done)
})
Expand All @@ -440,19 +400,9 @@ describe('.files (the MFS API part)', function () {
.then(() => {
return ipfs.files.read('/test-folder/test-file-2.txt')
})
.then((stream) => {
let buf = ''
stream
.on('error', (err) => {
expect(err).to.not.exist()
})
.on('data', (data) => {
buf += data
})
.on('end', () => {
expect(buf).to.be.equal('hello world')
done()
})
.then((buf) => {
expect(buf.toString()).to.be.equal('hello world')
done()
})
.catch(done)
})
Expand Down Expand Up @@ -482,19 +432,9 @@ describe('.files (the MFS API part)', function () {
if (!isNode) { return done() }

ipfs.files.read('/test-folder/test-file')
.then((stream) => {
let buf = ''
stream
.on('error', (err) => {
expect(err).to.not.exist()
})
.on('data', (data) => {
buf += data
})
.on('end', () => {
expect(Buffer.from(buf)).to.eql(testfile)
done()
})
.then((buf) => {
expect(Buffer.from(buf)).to.eql(testfile)
done()
})
})

Expand Down