Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

Commit

Permalink
begin block spec and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nginnever committed Jul 2, 2016
1 parent dbb23f6 commit 9910d69
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 0 deletions.
39 changes: 39 additions & 0 deletions API/block/README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,41 @@
block API
=========

#### 'get'

> Get a raw IPFS block.
##### `Go` **WIP**

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

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

- Buffer, the raw Buffer of the multihash
- String, the base58 encoded version of the multihash

`callback` must follow `function (err, stream) {}` signature, where `err` is an error if the operation was not successful and `stream` is a readable stream of the file.

If no `callback` is passed, a promise is returned.

```js
ipfs.block.get(multihash, function (err, data) {
// data is the raw data contained in a block
})
```



#### 'put'

> Stores input as an IPFS block.
##### `Go` **WIP**



#### 'stat'

> Print information of a raw IPFS block.
##### `Go` **WIP**
86 changes: 86 additions & 0 deletions src/block.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/* eslint-env mocha */
/* globals apiClients */
'use strict'

const expect = require('chai').expect

module.exports = (common) => {
describe.only('.block', () => {
const blorbKey = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ'
const blorb = Buffer('blorb')

it('returns an error when putting an array of files', () => {
return apiClients.a.block.put([blorb, blorb], (err) => {
expect(err).to.be.an.instanceof(Error)
})
})

it('block.put', (done) => {
apiClients.a.block.put(blorb, (err, res) => {
expect(err).to.not.exist
expect(res).to.have.a.property('Key', 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ')
done()
})
})

it('block.get', (done) => {
apiClients.a.block.get(blorbKey, (err, res) => {
expect(err).to.not.exist

let buf = ''
res
.on('data', function (data) { buf += data })
.on('end', function () {
expect(buf).to.be.equal('blorb')
done()
})
})
})

it('block.stat', (done) => {
apiClients.a.block.stat(blorbKey, (err, res) => {
expect(err).to.not.exist
expect(res).to.have.property('Key')
expect(res).to.have.property('Size')
done()
})
})

describe('promise', () => {
it('returns an error when putting an array of files', () => {
return apiClients.a.block.put([blorb, blorb])
.catch((err) => {
expect(err).to.be.an.instanceof(Error)
})
})

it('block.put', () => {
return apiClients.a.block.put(blorb)
.then((res) => {
expect(res).to.have.a.property('Key', 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ')
})
})

it('block.get', (done) => {
return apiClients.a.block.get(blorbKey)
.then((res) => {
let buf = ''
res
.on('data', function (data) { buf += data })
.on('end', function () {
expect(buf).to.be.equal('blorb')
done()
})
})
})

it('block.stat', () => {
return apiClients.a.block.stat(blorbKey)
.then((res) => {
expect(res).to.have.property('Key')
expect(res).to.have.property('Size')
})
})
})
})
}
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
exports.all = () => {}
exports.object = require('./object')
exports.files = require('./files')
exports.block = require('./block')

0 comments on commit 9910d69

Please sign in to comment.