Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
fix: return the CID for dag-cbor nodes (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain authored Jun 12, 2019
1 parent 7910d19 commit 4159b90
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"joi": "^14.3.0",
"joi-browser": "^13.4.0",
"mortice": "^1.2.1",
"multicodec": "~0.5.1",
"multicodec": "~0.5.3",
"multihashes": "~0.4.14",
"once": "^1.4.0",
"promisify-es6": "^1.0.3",
Expand Down
8 changes: 8 additions & 0 deletions src/core/stat.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,13 @@ const statters = {
sizeLocal: undefined,
withLocality: false
}
},
'dag-cbor': (file) => {
return {
cid: file.cid,
local: undefined,
sizeLocal: undefined,
withLocality: false
}
}
}
12 changes: 12 additions & 0 deletions test/stat.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const expect = chai.expect
const crypto = require('crypto')
const createMfs = require('./helpers/create-mfs')
const createShardedDirectory = require('./helpers/create-sharded-directory')
const mc = require('multicodec')

describe('stat', () => {
let mfs
Expand Down Expand Up @@ -160,4 +161,15 @@ describe('stat', () => {
expect(stats.type).to.equal('file')
expect(stats.size).to.equal(7)
})

it('stats a dag-cbor node', async () => {
const path = '/cbor.node'
const node = {}
const cid = await mfs.ipld.put(node, mc.getNumber('dag-cbor'))
await mfs.cp(`/ipfs/${cid}`, path)

const stats = await mfs.stat(path)

expect(stats.cid.toString()).to.equal(cid.toString())
})
})

0 comments on commit 4159b90

Please sign in to comment.