Skip to content
This repository has been archived by the owner on Aug 11, 2021. It is now read-only.

Commit

Permalink
Merge pull request #4 from dignifiedquire/dignified
Browse files Browse the repository at this point in the history
dignified pipeline
  • Loading branch information
daviddias committed Apr 8, 2016
2 parents a4c0487 + 268062b commit 3099d06
Show file tree
Hide file tree
Showing 52 changed files with 108 additions and 35 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,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 @@
tests/repo-just-for-test*

# 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
19 changes: 19 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
language: node_js
node_js:
- '4'
- '5'

before_install:
- npm i -g npm
# Workaround for a permissions issue with Travis virtual machine images

addons:
firefox: 'latest'

before_script:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start

script:
- npm run lint
- npm test
15 changes: 10 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
"description": "JavaScript Implementation of Block and BlockService",
"main": "src/index.js",
"scripts": {
"test": "mocha tests/index.js",
"lint": "standard"
"lint": "dignified-lint",
"build": "dignified-build",
"test": "dignified-test",
"test:node": "dignified-test node",
"test:browser": "dignified-test browser",
"release": "dignified-release",
"coverage": "dignified-coverage"
},
"pre-commit": [
"lint",
Expand All @@ -30,17 +35,17 @@
"devDependencies": {
"bs58": "^3.0.0",
"chai": "^3.5.0",
"dignified.js": "^1.0.0",
"fs-blob-store": "^5.2.1",
"ipfs-repo": "^0.3.0",
"mocha": "^2.4.5",
"ncp": "^2.0.0",
"pre-commit": "^1.1.2",
"rimraf": "^2.5.1",
"standard": "^5.4.1"
"rimraf": "^2.5.1"
},
"dependencies": {
"async": "^1.5.2",
"bl": "^1.0.1",
"detect-node": "^2.0.3",
"multihashing": "^0.2.0"
}
}
9 changes: 5 additions & 4 deletions src/block-service.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
'use strict'

const Block = require('./block')
const bl = require('bl')
const async = require('async')

module.exports = BlockService

// BlockService is a hybrid block datastore. It stores data in a local
// datastore and may retrieve data from a remote Exchange.
// It uses an internal `datastore.Datastore` instance to store values.
function BlockService (ipfsRepo, exchange) {
this.addBlock = (block, callback) => {
var ws = ipfsRepo.datastore.createWriteStream(block.key)
const ws = ipfsRepo.datastore.createWriteStream(block.key)
ws.write(block.data)
ws.on('finish', callback)
ws.end()
Expand Down Expand Up @@ -44,7 +44,7 @@ function BlockService (ipfsRepo, exchange) {
return callback(new Error('Invalid batch of multihashes'))
}

var blocks = []
const blocks = []

async.each(multihashes, (multihash, next) => {
this.getBlock(multihash, (err, block) => {
Expand Down Expand Up @@ -77,3 +77,4 @@ function BlockService (ipfsRepo, exchange) {
}
}

module.exports = BlockService
10 changes: 6 additions & 4 deletions src/block.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
'use strict'
const util = require('./util')

// Immutable block of data

module.exports = Block

function Block (data) {
if (!data) { throw new Error('Block must be constructed with data') }

if (!(this instanceof Block)) { return new Block(data) }
if (!(this instanceof Block)) {
return new Block(data)
}

this.data = new Buffer(data)
this.key = util.hash(this.data)
}

module.exports = Block
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict'

exports.BlockService = require('./block-service.js')
exports.Block = require('./block.js')
exports.util = require('./util.js')
9 changes: 6 additions & 3 deletions src/util.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
var multihashing = require('multihashing')
'use strict'

const multihashing = require('multihashing')
const isNode = require('detect-node')

exports = module.exports

// Hash is the global IPFS hash function. uses multihash SHA2_256, 256 bits
exports.hash = (data) => { return multihashing(data, 'sha2-256') }
exports.isBrowser = () => { return !!global.window }
exports.hash = (data) => multihashing(data, 'sha2-256')
exports.isBrowser = () => !isNode
5 changes: 2 additions & 3 deletions tests/block-service-test.js → test/block-service-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* globals describe, it */

/* eslint-env mocha */
'use strict'

const expect = require('chai').expect
Expand All @@ -9,7 +8,7 @@ const BlockService = require('../src').BlockService
const IPFSRepo = require('ipfs-repo')

describe('block-service', () => {
var bs
let bs

it('create a block-service', (done) => {
const repo = new IPFSRepo(process.env.IPFS_PATH)
Expand Down
7 changes: 3 additions & 4 deletions tests/block-test.js → test/block-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* globals describe, it */

/* eslint-env mocha */
'use strict'

const expect = require('chai').expect
Expand All @@ -14,7 +13,7 @@ describe('block', () => {
})

it('fail to create an empty block', (done) => {
var b
let b
try {
b = new Block()
} catch (err) {
Expand All @@ -34,7 +33,7 @@ describe('block', () => {
// it from the original implementation
// It doesn't stricly verify the immutability of the Block object
const block = new Block("Can't change this!")
var key = block.key
let key = block.key
key = new Buffer('new key')

expect(key.equals(block.key)).to.equal(false)
Expand Down
6 changes: 6 additions & 0 deletions test/browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* eslint-env mocha */
'use strict'

describe.skip('blocks', () => {
it('works in the browser')
})
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
23 changes: 11 additions & 12 deletions tests/index.js → test/node.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* globals describe, before, after */

/* eslint-env mocha */
'use strict'

const fs = require('fs')
Expand All @@ -8,35 +7,35 @@ const rimraf = require('rimraf')
const expect = require('chai').expect

describe('blocks', () => {
const repoExample = process.cwd() + '/tests/example-repo'
const repoTests = process.cwd() + '/tests/repo-just-for-test' + Date.now()
const repoExample = process.cwd() + '/test/example-repo'
const repoTests = process.cwd() + '/test/repo-just-for-test' + Date.now()

before(done => {
ncp(repoExample, repoTests, err => {
before((done) => {
ncp(repoExample, repoTests, (err) => {
process.env.IPFS_PATH = repoTests
expect(err).to.equal(null)
done()
})
})

after(done => {
rimraf(repoTests, err => {
after((done) => {
rimraf(repoTests, (err) => {
expect(err).to.equal(null)
done()
})
})

const tests = fs.readdirSync(__dirname)
tests.filter(file => {
tests.filter((file) => {
if (file === 'index.js' ||
file === 'example-repo' ||
file.indexOf('repo-just-for-test') > -1 ||
file === 'browser.js') {
return false
} else {
return true
}
}).forEach(file => {

return true
}).forEach((file) => {
require('./' + file)
})
})

0 comments on commit 3099d06

Please sign in to comment.