-
Notifications
You must be signed in to change notification settings - Fork 16
Async Crypto Endeavour #4
Conversation
|
||
Creates a new block with raw data `data`. `type` can be either `'protobuf'` or `'ipld'`. | ||
|
||
#### `Block.create(data, key, [type, ] callback)` |
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.
Let's just go ahead and take from #5 the fact that .key becomes a function and make it an async function.
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.
@diasdavid done, please review the new api before I start propagating
@@ -38,13 +38,13 @@ | |||
"homepage": "https://github.com/ipfs/js-ipfs-block#readme", | |||
"devDependencies": { | |||
"aegir": "^8.0.0", |
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.
update to latest
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.
🛎
API looks good, needs:
|
fa9a47f
to
41fd06b
Compare
41fd06b
to
7941631
Compare
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.
Overall LGTM
- [`block.data`](#blockdata) | ||
- [`block.key`](#blockkey) | ||
- [`block.extension`](#blockextension) | ||
- [`block.key([hashFn,] callback)`](#blockkeyhashfn-callback) |
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.
s/hashFn/hashAlg
|
||
The [multihash][multihash] of the block's data, as a buffer. | ||
|
||
#### `block.key([hashFn,] callback)` |
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.
s/hashFn/hashAlg
set () { | ||
throw new Error('Tried to change an immutable block') | ||
} | ||
}) |
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.
👍
@@ -26,7 +37,18 @@ function Block (data) { | |||
hashFunc = 'sha2-256' | |||
} | |||
|
|||
multihashing(this.data, hashFunc, callback) | |||
if (this._cache[hashFunc]) { | |||
setImmediate(() => { |
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.
setImmediate
isn't supported by FF or Chrome, will it be a problem?
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.
hmm thanks for pointing this out, need to find a better solution :(
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.
setImmediate
is also used in 4 different places across the codebase. There is also polyfill for it if it comes to it.
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.
yeah we were shipping one before, but not anymore. As we already use async
I'm going to use async.setImmediate
http://caolan.github.io/async/docs.html#setImmediate
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.
fixed
b9f4187
to
488d68c
Compare
BREAKING CHANGE:
Constructor requires a hash now and there is now Block.create(data, type, cb)