Skip to content

Commit 6bd7422

Browse files
refactor: use new block interface
1 parent ca51a92 commit 6bd7422

File tree

8 files changed

+63
-49
lines changed

8 files changed

+63
-49
lines changed

package.json

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
"main": "lib/index.js",
66
"jsnext:main": "src/index.js",
77
"scripts": {
8-
"test": "aegir-test",
8+
"test": "PHANTOM=off aegir-test",
99
"test:node": "aegir-test node",
10-
"test:browser": "aegir-test browser",
10+
"test:browser": "PHANTOM=off aegir-test browser",
1111
"build": "aegir-build",
12-
"coverage": "aegir-coverage",
1312
"lint": "aegir-lint",
14-
"release": "aegir-release",
15-
"release-minor": "aegir-release --type minor",
16-
"release-major": "aegir-release --type major",
13+
"release": "PHANTOM=off aegir-release",
14+
"release-minor": "PHANTOM=off aegir-release --type minor",
15+
"release-major": "PHANTOM=off aegir-release --type major",
16+
"coverage": "aegir-coverage",
1717
"coverage-publish": "aegir-coverage publish"
1818
},
1919
"repository": {
@@ -42,6 +42,7 @@
4242
"rimraf": "^2.5.4"
4343
},
4444
"dependencies": {
45+
"async": "^2.0.1",
4546
"babel-runtime": "^6.11.6",
4647
"base32.js": "^0.1.0",
4748
"ipfs-block": "^0.3.0",
@@ -50,8 +51,6 @@
5051
"pull-defer": "^0.2.2",
5152
"pull-stream": "^3.4.5",
5253
"pull-write": "^1.1.0",
53-
"run-parallel": "^1.1.6",
54-
"run-series": "^1.1.4",
5554
"safe-buffer": "^5.0.1"
5655
},
5756
"license": "MIT",
@@ -67,4 +66,4 @@
6766
"nginnever <[email protected]>",
6867
"npmcdn-to-unpkg-bot <[email protected]>"
6968
]
70-
}
69+
}

src/stores/blockstore.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const Lock = require('lock')
66
const base32 = require('base32.js')
77
const path = require('path')
88
const write = require('pull-write')
9-
const parallel = require('run-parallel')
9+
const parallel = require('async/parallel')
1010
const defer = require('pull-defer/source')
1111

1212
const PREFIX_LENGTH = 5
@@ -63,9 +63,13 @@ exports.setUp = (basePath, BlobStore, locks) => {
6363
return deferred.abort(err)
6464
}
6565

66-
deferred.resolve(pull.values([
67-
new Block(Buffer.concat(data), ext)
68-
]))
66+
Block.create(Buffer.concat(data), ext, (err, block) => {
67+
if (err) {
68+
return deferred.abort(err)
69+
}
70+
71+
deferred.resolve(pull.values([block]))
72+
})
6973
}))
7074
)
7175
})

src/stores/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict'
22

33
const pull = require('pull-stream')
4-
const series = require('run-series')
4+
const series = require('async/series')
55

66
exports = module.exports
77

src/stores/locks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict'
22

33
const pull = require('pull-stream')
4-
const series = require('run-series')
4+
const series = require('async/series')
55

66
exports = module.exports
77

src/stores/version.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict'
22

33
const pull = require('pull-stream')
4-
const series = require('run-series')
4+
const series = require('async/series')
55
const toBuffer = require('safe-buffer').Buffer.from
66

77
exports = module.exports

test/blockstore-test.js

Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,40 @@ const expect = require('chai').expect
55
const Block = require('ipfs-block')
66
const mh = require('multihashes')
77
const pull = require('pull-stream')
8-
const parallel = require('run-parallel')
8+
const parallel = require('async/parallel')
9+
const waterfall = require('async/waterfall')
10+
const map = require('async/map')
911
const _ = require('lodash')
1012

1113
module.exports = (repo) => {
1214
describe('blockstore', () => {
1315
const helloKey = 'CIQLS/CIQLSTJHXGJU2PQIUUXFFV62PWV7VREE57RXUU4A52IIR55M4LX432I.data'
1416
const helloIpldKey = 'CIQO2/CIQO2EUTF47PSTAHSL54KUTDS2AAN2DH4URM7H5KRATUGQFCM4OUIQI.ipld'
15-
const blockCollection = _.range(100).map((i) => new Block(new Buffer(`hello-${i}-${Math.random()}`)))
17+
let blockCollection
18+
let b
19+
let ipldBlock
1620

1721
describe('.putStream', () => {
22+
before((done) => {
23+
parallel([
24+
(cb) => map(_.range(100), (i, cb) => {
25+
Block.create(`hello-${i}-${Math.random()}`, cb)
26+
}, cb),
27+
(cb) => Block.create('hello world', cb),
28+
(cb) => Block.create('hello world 2', 'ipld', cb)
29+
], (err, results) => {
30+
if (err) {
31+
return done(err)
32+
}
33+
34+
blockCollection = results[0]
35+
b = results[1]
36+
ipldBlock = results[2]
37+
done()
38+
})
39+
})
40+
1841
it('simple', (done) => {
19-
const b = new Block('hello world')
2042
pull(
2143
pull.values([b]),
2244
repo.blockstore.putStream(),
@@ -29,8 +51,6 @@ module.exports = (repo) => {
2951
})
3052

3153
it('multi write (locks)', (done) => {
32-
const b = new Block('hello world')
33-
3454
let i = 0
3555
const finish = (err, meta) => {
3656
expect(err).to.not.exist
@@ -68,9 +88,8 @@ module.exports = (repo) => {
6888
})
6989

7090
it('custom extension', function (done) {
71-
const b = new Block('hello world 2', 'ipld')
7291
pull(
73-
pull.values([b]),
92+
pull.values([ipldBlock]),
7493
repo.blockstore.putStream(),
7594
pull.collect((err, meta) => {
7695
expect(err).to.not.exist
@@ -94,8 +113,6 @@ module.exports = (repo) => {
94113

95114
describe('.getStream', () => {
96115
it('simple', (done) => {
97-
const b = new Block('hello world')
98-
99116
pull(
100117
repo.blockstore.getStream(b.key),
101118
pull.collect((err, data) => {
@@ -122,13 +139,11 @@ module.exports = (repo) => {
122139
})
123140

124141
it('custom extension', (done) => {
125-
const b = new Block('hello world 2', 'ipld')
126-
127142
pull(
128-
repo.blockstore.getStream(b.key, b.extension),
143+
repo.blockstore.getStream(ipldBlock.key, ipldBlock.extension),
129144
pull.collect((err, data) => {
130145
expect(err).to.not.exist
131-
expect(data[0]).to.be.eql(b)
146+
expect(data[0]).to.be.eql(ipldBlock)
132147

133148
done()
134149
})
@@ -148,8 +163,6 @@ module.exports = (repo) => {
148163

149164
describe('.has', () => {
150165
it('existing block', (done) => {
151-
const b = new Block('hello world')
152-
153166
repo.blockstore.has(b.key, (err, exists) => {
154167
expect(err).to.not.exist
155168
expect(exists).to.equal(true)
@@ -158,8 +171,6 @@ module.exports = (repo) => {
158171
})
159172

160173
it('with extension', (done) => {
161-
const b = new Block('hello world')
162-
163174
repo.blockstore.has(b.key, 'data', (err, exists) => {
164175
expect(err).to.not.exist
165176
expect(exists).to.equal(true)
@@ -168,9 +179,10 @@ module.exports = (repo) => {
168179
})
169180

170181
it('non existent block', (done) => {
171-
const b = new Block('wooot')
172-
173-
repo.blockstore.has(b.key, (err, exists) => {
182+
waterfall([
183+
(cb) => Block.create('wooot', cb),
184+
(block, cb) => repo.blockstore.has(block.key, cb)
185+
], (err, exists) => {
174186
expect(err).to.not.exist
175187
expect(exists).to.equal(false)
176188
done()
@@ -180,8 +192,6 @@ module.exports = (repo) => {
180192

181193
describe('.delete', () => {
182194
it('simple', (done) => {
183-
const b = new Block('hello world')
184-
185195
repo.blockstore.delete(b.key, (err) => {
186196
expect(err).to.not.exist
187197

@@ -194,16 +204,17 @@ module.exports = (repo) => {
194204
})
195205

196206
it('custom extension', (done) => {
197-
const b = new Block('hello world', 'ipld')
198-
199-
repo.blockstore.delete(b.key, b.extension, (err) => {
200-
expect(err).to.not.exist
201-
202-
repo.blockstore.has(b.key, b.extension, (err, exists) => {
207+
waterfall([
208+
(cb) => Block.create('hello world', 'ipld', cb),
209+
(block, cb) => repo.blockstore.delete(block.key, block.extension, (err) => {
203210
expect(err).to.not.exist
204-
expect(exists).to.equal(false)
205-
done()
206-
})
211+
cb(null, block)
212+
}),
213+
(block, cb) => repo.blockstore.has(block.key, block.extension, cb)
214+
], (err, exists) => {
215+
expect(err).to.not.exist
216+
expect(exists).to.equal(false)
217+
done()
207218
})
208219
})
209220
})

test/browser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
'use strict'
44

5-
const series = require('run-series')
5+
const series = require('async/series')
66
const Store = require('idb-pull-blob-store')
77
const _ = require('lodash')
88
const pull = require('pull-stream')

test/repo-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
'use strict'
33

44
const expect = require('chai').expect
5-
const series = require('run-series')
5+
const series = require('async/series')
66

77
const Repo = require('../src/index')
88

0 commit comments

Comments
 (0)