Skip to content

Commit 62b03ef

Browse files
refactor: use aegir
1 parent f298764 commit 62b03ef

11 files changed

+216
-65
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,6 @@ node_modules
3131

3232
# Optional REPL history
3333
.node_repl_history
34+
35+
lib
36+
dist

.npmignore

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
6+
# Runtime data
7+
pids
8+
*.pid
9+
*.seed
10+
11+
# Directory for instrumented libs generated by jscoverage/JSCover
12+
lib-cov
13+
14+
# Coverage directory used by tools like istanbul
15+
coverage
16+
17+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
18+
.grunt
19+
20+
# node-waf configuration
21+
.lock-wscript
22+
23+
# Compiled binary addons (http://nodejs.org/api/addons.html)
24+
build/Release
25+
26+
# Dependency directory
27+
node_modules
28+
29+
# Optional npm cache directory
30+
.npm
31+
32+
# Optional REPL history
33+
.node_repl_history
34+
35+
test

.travis.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
1+
sudo: false
12
language: node_js
23
node_js:
3-
- 'stable'
4+
- 4
5+
- 5
46

5-
addons:
6-
firefox: 'latest'
7+
# Make sure we have new NPM.
8+
before_install:
9+
- npm install -g npm
710

811
script:
12+
- npm run lint
913
- npm test
1014

15+
addons:
16+
firefox: 'latest'
17+
1118
before_script:
1219
- export DISPLAY=:99.0
1320
- sh -e /etc/init.d/xvfb start

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22

33
> abstract-blob-store implementation for indexeddb
44
5+
[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io)
6+
[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)
7+
[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)
8+
[![Travis CI](https://travis-ci.org/dignifiedquire/idb-plus-blob-store.svg?branch=master)](https://travis-ci.org/dignifiedquire/idb-plus-blob-store)
9+
[![Circle CI](https://circleci.com/gh/dignifiedquire/idb-plus-blob-store.svg?style=svg)](https://circleci.com/gh/dignifiedquire/idb-plus-blob-store)
10+
[![Dependency Status](https://david-dm.org/dignifiedquire/idb-plus-blob-store.svg?style=flat-square)](https://david-dm.org/dignifiedquire/idb-plus-blob-store) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)
11+
512
[![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)
613
[![blob-store-compatible](https://raw.githubusercontent.com/maxogden/abstract-blob-store/master/badge.png)](https://github.com/maxogden/abstract-blob-store)
7-
8-
9-
[![Build Status](http://img.shields.io/travis/maxogden/abstract-blob-store.svg?style=flat)](https://travis-ci.org/Dignifiedquire/idb-plus-blob-store)

circle.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
machine:
2+
node:
3+
version: stable
4+
5+
dependencies:
6+
pre:
7+
- google-chrome --version
8+
- wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
9+
- sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
10+
- sudo apt-get update
11+
- sudo apt-get --only-upgrade install google-chrome-stable
12+
- google-chrome --version

karma.conf.js

Lines changed: 0 additions & 25 deletions
This file was deleted.

package.json

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
"description": "Abstract Blob Store implementation for indexeddb",
55
"main": "src/index.js",
66
"scripts": {
7-
"lint": "standard",
8-
"test": "npm run lint && npm run test:browser",
9-
"test:browser": "karma start --single-run=true karma.conf.js",
10-
"test:debug": "karma start karma.conf.js"
7+
"lint": "aegir-lint",
8+
"test": "aegir-test browser",
9+
"build": "aegir-build browser",
10+
"release": "aegir-release browser"
1111
},
1212
"repository": {
1313
"type": "git",
@@ -22,21 +22,21 @@
2222
"homepage": "https://github.com/Dignifiedquire/idb-plus-blob-store#readme",
2323
"devDependencies": {
2424
"abstract-blob-store": "^3.2.0",
25-
"browserify": "^13.0.0",
26-
"karma": "^0.13.19",
27-
"karma-browserify": "^5.0.1",
28-
"karma-chrome-launcher": "^0.2.2",
29-
"karma-firefox-launcher": "^0.1.7",
30-
"karma-tap": "^1.0.3",
31-
"karma-tape-reporter": "^1.0.3",
32-
"standard": "^5.4.1",
33-
"tape": "^4.4.0",
34-
"watchify": "^3.7.0"
25+
"aegir": "^2.1.1",
26+
"bl": "^1.1.2",
27+
"chai": "^3.5.0",
28+
"pre-commit": "^1.1.2",
29+
"tape": "^4.4.0"
3530
},
3631
"dependencies": {
37-
"db.js": "^0.10.2",
32+
"db.js": "^0.15.0",
3833
"from2": "^2.1.0",
3934
"lodash.isundefined": "^3.0.1",
35+
"readable-stream": "^1.1.13",
4036
"typedarray-to-buffer": "^3.0.5"
41-
}
37+
},
38+
"pre-commit": [
39+
"lint",
40+
"test"
41+
]
4242
}

src/index.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
'use strict'
2+
13
var db = require('db.js')
24
var isUndefined = require('lodash.isundefined')
35
var from = require('from2')
46
var toBuffer = require('typedarray-to-buffer')
5-
var Transform = require('stream').Transform
7+
var Transform = require('readable-stream').Transform
68
var util = require('util')
79

810
function noop () {}
@@ -32,10 +34,15 @@ module.exports = Blobs
3234
Blobs.prototype.createWriteStream = function (opts, cb) {
3335
if (typeof opts === 'function') opts = {}
3436
if (typeof opts === 'string') opts = {key: opts}
37+
if (opts.name && isUndefined(opts.key)) opts.key = opts.name
3538
if (!cb) cb = noop
3639

3740
var self = this
38-
var key = !isUndefined(opts.key) ? opts.key : 'undefined'
41+
var key = opts.key
42+
43+
if (isUndefined(key)) {
44+
return cb(new Error('Missing key'))
45+
}
3946

4047
var FlushableStream = function (options) {
4148
Transform.call(this, options)
@@ -130,10 +137,16 @@ Blobs.prototype.createWriteStream = function (opts, cb) {
130137
}
131138

132139
Blobs.prototype.createReadStream = function (opts) {
140+
if (!opts) opts = {}
133141
if (typeof opts === 'string') opts = {key: opts}
142+
if (opts.name && isUndefined(opts.key)) opts.key = opts.name
134143

135144
var self = this
136-
var key = !isUndefined(opts.key) ? opts.key : 'undefined'
145+
var key = opts.key
146+
147+
if (isUndefined(key)) {
148+
throw new Error('Missing key')
149+
}
137150

138151
var buf = null
139152
var result = from(function (size, next) {

test/abstract.spec.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* eslint-env mocha */
2+
'use strict'
3+
4+
const tape = require('tape')
5+
const tests = require('abstract-blob-store/tests')
6+
7+
const blob = require('../src/')
8+
9+
describe('abstract-blob-store', () => {
10+
it('works', (done) => {
11+
const common = {
12+
setup (t, cb) {
13+
cb(null, blob())
14+
},
15+
teardown (t, store, obj, cb) {
16+
if (obj) return store.remove(obj, cb)
17+
cb()
18+
}
19+
}
20+
21+
tape.onFinish(done)
22+
tests(tape, common)
23+
})
24+
})

test/index.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

test/specific.spec.js

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/* eslint-env mocha */
2+
'use strict'
3+
4+
const expect = require('chai').expect
5+
const bl = require('bl')
6+
7+
const blob = require('../src')
8+
9+
describe('idb-plus-blob-store', () => {
10+
let store
11+
12+
before(() => {
13+
store = blob()
14+
})
15+
16+
describe('createWriteStream', () => {
17+
it('can write over an existing key', (done) => {
18+
const key = 'hello.txt'
19+
const input1 = 'hello'
20+
const input2 = 'world'
21+
22+
const ws1 = store.createWriteStream({key}, (err, blob) => {
23+
expect(err).to.not.exist
24+
expect(blob.key).to.be.eql(key)
25+
26+
const ws2 = store.createWriteStream({key}, (err, blob) => {
27+
expect(err).to.not.exist
28+
expect(blob.key).to.be.eql(key)
29+
30+
const rs = store.createReadStream(blob)
31+
rs.pipe(bl((err, res) => {
32+
expect(err).to.not.exist
33+
expect(res.toString()).to.be.eql(input2)
34+
done()
35+
}))
36+
})
37+
38+
ws2.write(input2)
39+
ws2.end()
40+
})
41+
42+
ws1.write(input1)
43+
ws1.end()
44+
})
45+
46+
it('throws on missing key', (done) => {
47+
store.createWriteStream({}, (err, blob) => {
48+
expect(err.message).to.be.eql('Missing key')
49+
done()
50+
})
51+
})
52+
53+
it('uses name as key', (done) => {
54+
const name = 'hello.txt'
55+
const ws = store.createWriteStream({name}, (err, blob) => {
56+
expect(err).to.not.exist
57+
expect(blob.key).to.be.eql(name)
58+
done()
59+
})
60+
ws.end()
61+
})
62+
})
63+
64+
describe('createReadStream', () => {
65+
it('throws on missing key', () => {
66+
expect(
67+
() => store.createReadStream({})
68+
).to.throw(
69+
'Missing key'
70+
)
71+
})
72+
73+
it('uses name as key', (done) => {
74+
const name = 'hello.txt'
75+
const ws = store.createWriteStream({name}, (err, blob) => {
76+
expect(err).to.not.exist
77+
expect(blob.key).to.be.eql(name)
78+
79+
const rs = store.createReadStream({name})
80+
81+
rs.pipe(bl((err, res) => {
82+
expect(err).to.not.exist
83+
expect(res.toString()).to.be.eql('hello')
84+
85+
done()
86+
}))
87+
})
88+
89+
ws.write('hello')
90+
ws.end()
91+
})
92+
})
93+
})

0 commit comments

Comments
 (0)