-
Notifications
You must be signed in to change notification settings - Fork 37
Binary resolver #90
Binary resolver #90
Changes from 3 commits
42dd425
a704700
e011e0c
e200e9e
7baa91c
aae53c3
a38ce51
d65bbcd
f29db2d
8805650
5159ca3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use strict' | ||
const CID = require('cids') | ||
|
||
// binary resolver | ||
module.exports = { | ||
resolver: { | ||
multicodec: 'base2', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I remember that discussed this in great length and the reasons why raw is different from base2. If I remember correctly, you pointed out that base2 is actually incorrect . I'm not finding the issue where that discussion happened (I think it was in IRC, our bad for not logging it). All of that said, let's use the codec There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Base2 codec is literal stream of ASCI: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Kubuxu does |
||
resolve: (ipfsBlock, path, callback) => { | ||
callback(null, { | ||
value: ipfsBlock.data, | ||
remainderPath: path | ||
}) | ||
}, | ||
tree: (ipfsBlock, options, callback) => { | ||
callback(null, []) | ||
} | ||
}, | ||
util: { | ||
deserialize: (data, cb) => { | ||
cb(null, data) | ||
}, | ||
serialize: (data, cb) => { | ||
cb(null, data) | ||
}, | ||
cid: (data, cb) => { | ||
cb(null, new CID(1, 'base2', data)) | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
const chai = require('chai') | ||
const dirtyChai = require('dirty-chai') | ||
const expect = chai.expect | ||
chai.use(dirtyChai) | ||
const IpfsBlock = require('ipfs-block') | ||
const CID = require('cids') | ||
const ipldBin = require('../src/ipldBin') | ||
|
||
module.exports = () => { | ||
describe('IPLD Resolver with ipld-bin (binary resolver)', () => { | ||
it('resolves an ipfsBlock to its data', (done) => { | ||
const buffer = Buffer.from('deadbeef', 'hex') | ||
const cid = new CID('zDvjKAA4iXx') | ||
const ipfsBlock = new IpfsBlock(buffer, cid) | ||
ipldBin.resolver.resolve(ipfsBlock, '/hello/world', (err, result) => { | ||
expect(err).to.not.exist() | ||
expect(result).to.exist() | ||
expect(Buffer.isBuffer(result.value)).to.be.true() | ||
expect(result.value.toString('hex')).to.be.eql('deadbeef') | ||
expect(result.remainderPath).to.be.eql('/hello/world') | ||
done() | ||
}) | ||
}) | ||
|
||
it('trees an empty array', (done) => { | ||
const buffer = Buffer.from('deadbeef', 'hex') | ||
const cid = new CID('zDvjKAA4iXx') | ||
const ipfsBlock = new IpfsBlock(buffer, cid) | ||
ipldBin.resolver.tree(ipfsBlock, {}, (err, result) => { | ||
expect(err).to.not.exist() | ||
expect(result).to.exist() | ||
expect(result.length).to.eql(0) | ||
done() | ||
}) | ||
}) | ||
|
||
it('creates a cid with the currect multicodec', (done) => { | ||
const buffer = Buffer.from('deadbeef', 'hex') | ||
// const cid = new CID('zDvjKAA4iXx') | ||
// const ipfsBlock = new IpfsBlock(buffer, cid) | ||
ipldBin.util.cid(buffer, (err, cid) => { | ||
expect(err).to.not.exist() | ||
expect(cid).to.exist() | ||
expect(cid.codec).to.eql('base2') | ||
done() | ||
}) | ||
}) | ||
|
||
it('serializes to the same value', (done) => { | ||
const buffer = Buffer.from('deadbeef', 'hex') | ||
// const cid = new CID('zDvjKAA4iXx') | ||
// const ipfsBlock = new IpfsBlock(buffer, cid) | ||
ipldBin.util.serialize(buffer, (err, result) => { | ||
expect(err).to.not.exist() | ||
expect(result).to.exist() | ||
expect(result.toString('hex')).to.eql(buffer.toString('hex')) | ||
done() | ||
}) | ||
}) | ||
|
||
it('deserializes to the same value', (done) => { | ||
const buffer = Buffer.from('deadbeef', 'hex') | ||
// const cid = new CID('zDvjKAA4iXx') | ||
// const ipfsBlock = new IpfsBlock(buffer, cid) | ||
ipldBin.util.deserialize(buffer, (err, result) => { | ||
expect(err).to.not.exist() | ||
expect(result).to.exist() | ||
expect(result.toString('hex')).to.eql(buffer.toString('hex')) | ||
done() | ||
}) | ||
}) | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kumavis mind moving this resolver to here https://github.com/ipld/js-ipld-raw ?