diff --git a/src/files/ls.js b/src/files/ls.js index e87f07719..fe6ee275e 100644 --- a/src/files/ls.js +++ b/src/files/ls.js @@ -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) }) } diff --git a/src/files/stat.js b/src/files/stat.js index 845901b98..d53da0dab 100644 --- a/src/files/stat.js +++ b/src/files/stat.js @@ -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) }) } diff --git a/test/files.spec.js b/test/files.spec.js index 6806643eb..c1ccc56d1 100644 --- a/test/files.spec.js +++ b/test/files.spec.js @@ -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() }) }) @@ -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() @@ -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) }) }) @@ -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' }) }) })