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

Commit 98000af

Browse files
hacdiasdaviddias
authored andcommitted
feat (breaking change): normalize fields on files.ls and flatten output (#670)
1 parent 5803d39 commit 98000af

File tree

3 files changed

+37
-16
lines changed

3 files changed

+37
-16
lines changed

src/files/ls.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,27 @@
22

33
const promisify = require('promisify-es6')
44

5+
const transform = function (res, callback) {
6+
callback(null, res.Entries.map((entry) => {
7+
return {
8+
name: entry.Name,
9+
type: entry.Type,
10+
size: entry.Size,
11+
hash: entry.Hash
12+
}
13+
}))
14+
}
15+
516
module.exports = (send) => {
617
return promisify((args, opts, callback) => {
718
if (typeof (opts) === 'function') {
819
callback = opts
920
opts = {}
1021
}
11-
return send({
22+
return send.andTransform({
1223
path: 'files/ls',
1324
args: args,
1425
qs: opts
15-
}, callback)
26+
}, transform, callback)
1627
})
1728
}

src/files/stat.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,26 @@
22

33
const promisify = require('promisify-es6')
44

5+
const transform = function (res, callback) {
6+
callback(null, {
7+
type: res.Type,
8+
blocks: res.Blocks,
9+
size: res.Size,
10+
hash: res.Hash,
11+
cumulativeSize: res.CumulativeSize
12+
})
13+
}
14+
515
module.exports = (send) => {
616
return promisify((args, opts, callback) => {
717
if (typeof (opts) === 'function') {
818
callback = opts
919
opts = {}
1020
}
11-
send({
21+
send.andTransform({
1222
path: 'files/stat',
1323
args: args,
1424
qs: opts
15-
}, callback)
25+
}, transform, callback)
1626
})
1727
}

test/files.spec.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ describe('.files (the MFS API part)', function () {
231231
it('files.ls', (done) => {
232232
ipfs.files.ls('/test-folder', (err, res) => {
233233
expect(err).to.not.exist()
234-
expect(res.Entries.length).to.equal(1)
234+
expect(res.length).to.equal(1)
235235
done()
236236
})
237237
})
@@ -286,11 +286,11 @@ describe('.files (the MFS API part)', function () {
286286
ipfs.files.stat('/test-folder/test-file', (err, res) => {
287287
expect(err).to.not.exist()
288288
expect(res).to.deep.equal({
289-
Hash: 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP',
290-
Size: 12,
291-
CumulativeSize: 20,
292-
Blocks: 0,
293-
Type: 'file'
289+
hash: 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP',
290+
size: 12,
291+
cumulativeSize: 20,
292+
blocks: 0,
293+
type: 'file'
294294
})
295295

296296
done()
@@ -404,7 +404,7 @@ describe('.files (the MFS API part)', function () {
404404
it('files.ls', () => {
405405
return ipfs.files.ls('/test-folder')
406406
.then((res) => {
407-
expect(res.Entries.length).to.equal(1)
407+
expect(res.length).to.equal(1)
408408
})
409409
})
410410

@@ -458,11 +458,11 @@ describe('.files (the MFS API part)', function () {
458458
return ipfs.files.stat('/test-folder/test-file')
459459
.then((res) => {
460460
expect(res).to.deep.equal({
461-
Hash: 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP',
462-
Size: 12,
463-
CumulativeSize: 20,
464-
Blocks: 0,
465-
Type: 'file'
461+
hash: 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP',
462+
size: 12,
463+
cumulativeSize: 20,
464+
blocks: 0,
465+
type: 'file'
466466
})
467467
})
468468
})

0 commit comments

Comments
 (0)