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

breaking change: normalize fields and flatten output #670

Merged
merged 2 commits into from
Jan 21, 2018
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
15 changes: 13 additions & 2 deletions src/files/ls.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,27 @@

const promisify = require('promisify-es6')

const transform = function (res, callback) {
callback(null, res.Entries.map((entry) => {
return {
name: entry.Name,
type: entry.Type,
size: entry.Size,
hash: entry.Hash
}
}))
}

module.exports = (send) => {
return promisify((args, opts, callback) => {
if (typeof (opts) === 'function') {
callback = opts
opts = {}
}
return send({
return send.andTransform({
path: 'files/ls',
args: args,
qs: opts
}, callback)
}, transform, callback)
})
}
14 changes: 12 additions & 2 deletions src/files/stat.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,26 @@

const promisify = require('promisify-es6')

const transform = function (res, callback) {
callback(null, {
type: res.Type,
blocks: res.Blocks,
size: res.Size,
hash: res.Hash,
cumulativeSize: res.CumulativeSize
})
}

module.exports = (send) => {
return promisify((args, opts, callback) => {
if (typeof (opts) === 'function') {
callback = opts
opts = {}
}
send({
send.andTransform({
path: 'files/stat',
args: args,
qs: opts
}, callback)
}, transform, callback)
})
}
24 changes: 12 additions & 12 deletions test/files.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ describe('.files (the MFS API part)', function () {
it('files.ls', (done) => {
ipfs.files.ls('/test-folder', (err, res) => {
expect(err).to.not.exist()
expect(res.Entries.length).to.equal(1)
expect(res.length).to.equal(1)
done()
})
})
Expand Down Expand Up @@ -286,11 +286,11 @@ describe('.files (the MFS API part)', function () {
ipfs.files.stat('/test-folder/test-file', (err, res) => {
expect(err).to.not.exist()
expect(res).to.deep.equal({
Hash: 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP',
Size: 12,
CumulativeSize: 20,
Blocks: 0,
Type: 'file'
hash: 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP',
size: 12,
cumulativeSize: 20,
blocks: 0,
type: 'file'
})

done()
Expand Down Expand Up @@ -404,7 +404,7 @@ describe('.files (the MFS API part)', function () {
it('files.ls', () => {
return ipfs.files.ls('/test-folder')
.then((res) => {
expect(res.Entries.length).to.equal(1)
expect(res.length).to.equal(1)
})
})

Expand Down Expand Up @@ -458,11 +458,11 @@ describe('.files (the MFS API part)', function () {
return ipfs.files.stat('/test-folder/test-file')
.then((res) => {
expect(res).to.deep.equal({
Hash: 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP',
Size: 12,
CumulativeSize: 20,
Blocks: 0,
Type: 'file'
hash: 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP',
size: 12,
cumulativeSize: 20,
blocks: 0,
type: 'file'
})
})
})
Expand Down