Skip to content

Commit

Permalink
refactor: use aegir
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Apr 22, 2016
1 parent f298764 commit 62b03ef
Show file tree
Hide file tree
Showing 11 changed files with 216 additions and 65 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ node_modules

# Optional REPL history
.node_repl_history

lib
dist
35 changes: 35 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Logs
logs
*.log
npm-debug.log*

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
node_modules

# Optional npm cache directory
.npm

# Optional REPL history
.node_repl_history

test
13 changes: 10 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
sudo: false
language: node_js
node_js:
- 'stable'
- 4
- 5

addons:
firefox: 'latest'
# Make sure we have new NPM.
before_install:
- npm install -g npm

script:
- npm run lint
- npm test

addons:
firefox: 'latest'

before_script:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

> abstract-blob-store implementation for indexeddb
[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io)
[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)
[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)
[![Travis CI](https://travis-ci.org/dignifiedquire/idb-plus-blob-store.svg?branch=master)](https://travis-ci.org/dignifiedquire/idb-plus-blob-store)
[![Circle CI](https://circleci.com/gh/dignifiedquire/idb-plus-blob-store.svg?style=svg)](https://circleci.com/gh/dignifiedquire/idb-plus-blob-store)
[![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)

[![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)
[![blob-store-compatible](https://raw.githubusercontent.com/maxogden/abstract-blob-store/master/badge.png)](https://github.com/maxogden/abstract-blob-store)


[![Build Status](http://img.shields.io/travis/maxogden/abstract-blob-store.svg?style=flat)](https://travis-ci.org/Dignifiedquire/idb-plus-blob-store)
12 changes: 12 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
machine:
node:
version: stable

dependencies:
pre:
- google-chrome --version
- wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
- sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
- sudo apt-get update
- sudo apt-get --only-upgrade install google-chrome-stable
- google-chrome --version
25 changes: 0 additions & 25 deletions karma.conf.js

This file was deleted.

32 changes: 16 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"description": "Abstract Blob Store implementation for indexeddb",
"main": "src/index.js",
"scripts": {
"lint": "standard",
"test": "npm run lint && npm run test:browser",
"test:browser": "karma start --single-run=true karma.conf.js",
"test:debug": "karma start karma.conf.js"
"lint": "aegir-lint",
"test": "aegir-test browser",
"build": "aegir-build browser",
"release": "aegir-release browser"
},
"repository": {
"type": "git",
Expand All @@ -22,21 +22,21 @@
"homepage": "https://github.com/Dignifiedquire/idb-plus-blob-store#readme",
"devDependencies": {
"abstract-blob-store": "^3.2.0",
"browserify": "^13.0.0",
"karma": "^0.13.19",
"karma-browserify": "^5.0.1",
"karma-chrome-launcher": "^0.2.2",
"karma-firefox-launcher": "^0.1.7",
"karma-tap": "^1.0.3",
"karma-tape-reporter": "^1.0.3",
"standard": "^5.4.1",
"tape": "^4.4.0",
"watchify": "^3.7.0"
"aegir": "^2.1.1",
"bl": "^1.1.2",
"chai": "^3.5.0",
"pre-commit": "^1.1.2",
"tape": "^4.4.0"
},
"dependencies": {
"db.js": "^0.10.2",
"db.js": "^0.15.0",
"from2": "^2.1.0",
"lodash.isundefined": "^3.0.1",
"readable-stream": "^1.1.13",
"typedarray-to-buffer": "^3.0.5"
}
},
"pre-commit": [
"lint",
"test"
]
}
19 changes: 16 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
'use strict'

var db = require('db.js')
var isUndefined = require('lodash.isundefined')
var from = require('from2')
var toBuffer = require('typedarray-to-buffer')
var Transform = require('stream').Transform
var Transform = require('readable-stream').Transform
var util = require('util')

function noop () {}
Expand Down Expand Up @@ -32,10 +34,15 @@ module.exports = Blobs
Blobs.prototype.createWriteStream = function (opts, cb) {
if (typeof opts === 'function') opts = {}
if (typeof opts === 'string') opts = {key: opts}
if (opts.name && isUndefined(opts.key)) opts.key = opts.name
if (!cb) cb = noop

var self = this
var key = !isUndefined(opts.key) ? opts.key : 'undefined'
var key = opts.key

if (isUndefined(key)) {
return cb(new Error('Missing key'))
}

var FlushableStream = function (options) {
Transform.call(this, options)
Expand Down Expand Up @@ -130,10 +137,16 @@ Blobs.prototype.createWriteStream = function (opts, cb) {
}

Blobs.prototype.createReadStream = function (opts) {
if (!opts) opts = {}
if (typeof opts === 'string') opts = {key: opts}
if (opts.name && isUndefined(opts.key)) opts.key = opts.name

var self = this
var key = !isUndefined(opts.key) ? opts.key : 'undefined'
var key = opts.key

if (isUndefined(key)) {
throw new Error('Missing key')
}

var buf = null
var result = from(function (size, next) {
Expand Down
24 changes: 24 additions & 0 deletions test/abstract.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* eslint-env mocha */
'use strict'

const tape = require('tape')
const tests = require('abstract-blob-store/tests')

const blob = require('../src/')

describe('abstract-blob-store', () => {
it('works', (done) => {
const common = {
setup (t, cb) {
cb(null, blob())
},
teardown (t, store, obj, cb) {
if (obj) return store.remove(obj, cb)
cb()
}
}

tape.onFinish(done)
tests(tape, common)
})
})
15 changes: 0 additions & 15 deletions test/index.js

This file was deleted.

93 changes: 93 additions & 0 deletions test/specific.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/* eslint-env mocha */
'use strict'

const expect = require('chai').expect
const bl = require('bl')

const blob = require('../src')

describe('idb-plus-blob-store', () => {
let store

before(() => {
store = blob()
})

describe('createWriteStream', () => {
it('can write over an existing key', (done) => {
const key = 'hello.txt'
const input1 = 'hello'
const input2 = 'world'

const ws1 = store.createWriteStream({key}, (err, blob) => {
expect(err).to.not.exist
expect(blob.key).to.be.eql(key)

const ws2 = store.createWriteStream({key}, (err, blob) => {
expect(err).to.not.exist
expect(blob.key).to.be.eql(key)

const rs = store.createReadStream(blob)
rs.pipe(bl((err, res) => {
expect(err).to.not.exist
expect(res.toString()).to.be.eql(input2)
done()
}))
})

ws2.write(input2)
ws2.end()
})

ws1.write(input1)
ws1.end()
})

it('throws on missing key', (done) => {
store.createWriteStream({}, (err, blob) => {
expect(err.message).to.be.eql('Missing key')
done()
})
})

it('uses name as key', (done) => {
const name = 'hello.txt'
const ws = store.createWriteStream({name}, (err, blob) => {
expect(err).to.not.exist
expect(blob.key).to.be.eql(name)
done()
})
ws.end()
})
})

describe('createReadStream', () => {
it('throws on missing key', () => {
expect(
() => store.createReadStream({})
).to.throw(
'Missing key'
)
})

it('uses name as key', (done) => {
const name = 'hello.txt'
const ws = store.createWriteStream({name}, (err, blob) => {
expect(err).to.not.exist
expect(blob.key).to.be.eql(name)

const rs = store.createReadStream({name})

rs.pipe(bl((err, res) => {
expect(err).to.not.exist
expect(res.toString()).to.be.eql('hello')

done()
}))
})

ws.write('hello')
ws.end()
})
})
})

0 comments on commit 62b03ef

Please sign in to comment.