Skip to content
This repository has been archived by the owner on Dec 6, 2022. It is now read-only.

Commit

Permalink
docs(api): add it
Browse files Browse the repository at this point in the history
  • Loading branch information
Charlie authored and dignifiedquire committed Jan 22, 2017
1 parent 1e98996 commit ca1db3b
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ const setImmediate = require('async/setImmediate')

module.exports = Block

// Immutable block of data
/**
* Represents an immutable block of data that is uniquely referenced with a multihash key.
*
* @constructor
* @param {Buffer | string} data - The data to be stored in the block as a buffer or a UTF8 string.
* @example
* const block = new Block('a012d83b20f9371...')
*/
function Block (data) {
if (!(this instanceof Block)) {
return new Block(data)
Expand Down Expand Up @@ -36,6 +43,18 @@ function Block (data) {
}
})

/**
* Creates a unique multihash key of this block.
*
* @param {string} [hashFunc='sha2-256'] - The hash function to use.
* @param {function(Error, Multihash)} callback - The callback to execute on completion.
* @returns {void}
* @example
* block.key((multihash) => {
* console.log(multihash)
* })
* // 'QmeoBGh5g5kHgK3xppJ1...'
**/
this.key = (hashFunc, callback) => {
if (typeof hashFunc === 'function') {
callback = hashFunc
Expand Down

0 comments on commit ca1db3b

Please sign in to comment.