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

Commit

Permalink
feat: update block spec to support CID
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias committed Jan 31, 2017
1 parent 00fe0f7 commit 35e2353
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
24 changes: 16 additions & 8 deletions API/block/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@ block API
##### `Go` **WIP**

##### `JavaScript` - ipfs.block.get(multihash, [options, callback])
##### `JavaScript` - ipfs.block.get(cid, [options, callback])

`multihash` is a [multihash][multihash] which can be passed as:
`cid` is a [cid][cid] which can be passed as:

- Buffer, the raw Buffer of the multihash
- Buffer, the raw Buffer of the cid
- CID, a CID instance
- String, the base58 encoded version of the multihash

`callback` must follow `function (err, block) {}` signature, where `err` is an error if the operation was not successful and `block` is a [Block][block] type object, containing both the data and the hash of the block.

```js
ipfs.block.get(multihash, function (err, block) {
ipfs.block.get(cid, function (err, block) {
if (err) {
throw err
}
Expand All @@ -38,13 +39,19 @@ If no `callback` is passed, a promise is returned.
##### `Go` **WIP**

##### `JavaScript` - ipfs.block.put(block, [callback])
##### `JavaScript` - ipfs.block.put(block, cid, [callback])

Where `block` can be:

- `Buffer` - the raw bytes of the Block
- [`Block`][block] instance

`cid` is a [cid][cid] which can be passed as:

- Buffer, the raw Buffer of the cid
- CID, a CID instance
- String, the base58 encoded version of the multihash

`callback` has the signature `function (err, block) {}`, where `err` is an error if the operation was not successful and `block` is a [Block][block] type object, containing both the data and the hash of the block.

If no `callback` is passed, a promise is returned.
Expand All @@ -55,18 +62,19 @@ If no `callback` is passed, a promise is returned.
##### `Go` **WIP**

##### `JavaScript` - ipfs.block.stat(multihash, [callback])
##### `JavaScript` - ipfs.block.stat(cid, [callback])

`multihash` is a [multihash][multihash] which can be passed as:
`cid` is a [cid][cid] which can be passed as:

- `Buffer`, the raw Buffer of the multihash (or of and encoded version)
- `String`, the toString version of the multihash (or of an encoded version)
- CID, a CID instance

`callback` must follow the signature `function (err, stats) {}`, where `err` is an error if the operation was not successful and `stats` is an object with the format:`

```JavaScript
{
key: 'QmPTkMuuL6PD8L2SwTwbcs1NPg14U8mRzerB1ZrrBrkSDD',
cid: 'QmPTkMuuL6PD8L2SwTwbcs1NPg14U8mRzerB1ZrrBrkSDD',
size: 10
}
```
Expand Down
7 changes: 2 additions & 5 deletions src/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ module.exports = (common) => {
})
})

after((done) => {
common.teardown(done)
})
after((done) => common.teardown(done))

describe('callback API', () => {
it('.put a buffer', (done) => {
Expand Down Expand Up @@ -123,7 +121,6 @@ module.exports = (common) => {
it.skip('block.rm', (done) => {}) // TODO once block.rm is shipped in go-ipfs
})

describe('promise API', () => {
})
describe('promise API', () => {})
})
}

0 comments on commit 35e2353

Please sign in to comment.