Skip to content

Commit 495a9b9

Browse files
committed
Merge pull request #36 from ipfs/ipld
Add configurable extension support
2 parents 63fd8f8 + 6ec29c0 commit 495a9b9

File tree

46 files changed

+149
-120
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+149
-120
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
test/test-repo-for*
2+
13
# Logs
24
logs
35
*.log
@@ -26,3 +28,6 @@ build
2628
# Dependency directory
2729
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
2830
node_modules
31+
32+
dist
33+
lib

.npmignore

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
test
2+
3+
# Logs
4+
logs
5+
*.log
6+
7+
coverage
8+
9+
# Runtime data
10+
pids
11+
*.pid
12+
*.seed
13+
14+
# Directory for instrumented libs generated by jscoverage/JSCover
15+
lib-cov
16+
17+
# Coverage directory used by tools like istanbul
18+
coverage
19+
20+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
21+
.grunt
22+
23+
# node-waf configuration
24+
.lock-wscript
25+
26+
build
27+
28+
# Dependency directory
29+
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
30+
node_modules

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ before_install:
1111
- npm i -g npm
1212
# Workaround for a permissions issue with Travis virtual machine images
1313
script:
14+
- npm run lint
1415
- npm test
1516

1617
before_script:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ js-ipfs-repo
88
[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)
99
[![Build Status](https://travis-ci.org/ipfs/js-ipfs-repo.svg)](https://travis-ci.org/ipfs/js-ipfs-repo)
1010
![](https://img.shields.io/badge/coverage-90%25-yellow.svg?style=flat-square) [![Dependency Status](https://david-dm.org/diasdavid/js-peer-id.svg?style=flat-square)](https://david-dm.org/ipfs/js-ipfs-repo)
11-
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)
11+
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard) [![dignified.js](https://img.shields.io/badge/uses-dignified.js-blue.svg?style=flat-square)](https://github.com/dignifiedquire/dignified.js)
1212

1313
## Description
1414

circle.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
dependencies:
2+
pre:
3+
- npm i -g npm
4+
5+
machine:
6+
node:
7+
version: stable

karma.conf.js

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

package.json

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
"description": "IPFS Repo implementation",
55
"main": "src/index.js",
66
"scripts": {
7-
"test": "npm run test:node && npm run test:browser",
8-
"test:node": "mocha tests/node-tests.js",
9-
"test:browser": "karma start karma.conf.js",
10-
"coverage": "istanbul cover --print both -- _mocha tests/node-tests.js",
11-
"lint": "standard"
7+
"test": "dignified-test",
8+
"test:node": "dignified-test node",
9+
"test:browser": "dignified-test browser",
10+
"build": "dignified-build",
11+
"coverage": "dignified-coverage",
12+
"lint": "dignified-lint",
13+
"release": "dignified-release"
1214
},
1315
"repository": {
1416
"type": "git",
@@ -24,34 +26,18 @@
2426
"homepage": "https://github.com/ipfs/js-ipfs-repo",
2527
"devDependencies": {
2628
"async": "^1.5.2",
27-
"babel-core": "^6.7.2",
28-
"babel-loader": "^6.2.4",
29-
"babel-polyfill": "^6.7.2",
30-
"babel-preset-es2015": "^6.6.0",
3129
"bl": "^1.1.2",
3230
"bs58": "^3.0.0",
3331
"buffer-loader": "^0.0.1",
3432
"chai": "^3.5.0",
33+
"dignified.js": "^1.0.0",
3534
"fs-blob-store": "^5.2.1",
3635
"idb-plus-blob-store": "^1.0.0",
37-
"istanbul": "^0.4.2",
38-
"karma": "^0.13.22",
39-
"karma-chrome-launcher": "^0.2.2",
40-
"karma-cli": "^0.1.2",
41-
"karma-firefox-launcher": "^0.1.7",
42-
"karma-mocha": "^0.2.2",
43-
"karma-phantomjs-launcher": "^1.0.0",
44-
"karma-spec-reporter": "0.0.26",
45-
"karma-webpack": "^1.7.0",
4636
"local-storage-blob-store": "0.0.3",
4737
"lodash": "^4.6.1",
48-
"mocha": "^2.4.5",
4938
"ncp": "^2.0.0",
50-
"phantomjs-prebuilt": "^2.1.6",
5139
"pre-commit": "^1.1.2",
52-
"rimraf": "^2.5.2",
53-
"standard": "^6.0.8",
54-
"webpack": "github:diasdavid/webpack#webpack-1"
40+
"rimraf": "^2.5.2"
5541
},
5642
"dependencies": {
5743
"bl": "^1.1.2",

src/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22

33
const stores = require('./stores')
44

5-
exports = module.exports = Repo
6-
75
function Repo (repoPath, options) {
86
if (!options) { throw new Error('missing options param') }
97
if (!options.stores) { throw new Error('missing options.stores param') }
108

119
// If options.stores is an abstract-blob-store instead of a map, use it for
1210
// all stores.
13-
if (options.stores.prototype && options.stores.prototype.createWriteSteam) {
14-
var store = options.stores
11+
if (options.stores.prototype && options.stores.prototype.createWriteStream) {
12+
const store = options.stores
1513
options.stores = {
1614
keys: store,
1715
config: store,
@@ -70,3 +68,5 @@ function Repo (repoPath, options) {
7068
// .logs
7169
// .setUp(repoPath, options.stores.logs, this.locks)
7270
}
71+
72+
exports = module.exports = Repo

src/stores/datastore.js

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,50 @@ const PREFIX_LENGTH = 8
44

55
exports = module.exports
66

7+
function multihashToPath (multihash, extension) {
8+
extension = extension || 'data'
9+
const filename = `${multihash.toString('hex')}.${extension}`
10+
const folder = filename.slice(0, PREFIX_LENGTH)
11+
const path = folder + '/' + filename
12+
13+
return path
14+
}
15+
716
exports.setUp = (basePath, blobStore, locks) => {
817
const store = blobStore(basePath + '/blocks')
918

1019
return {
11-
createReadStream: (multihash) => {
12-
const path = multihashToPath(multihash)
20+
createReadStream: (multihash, extension) => {
21+
const path = multihashToPath(multihash, extension)
1322
return store.createReadStream(path)
1423
},
1524

16-
createWriteStream: (multihash, cb) => {
17-
const path = multihashToPath(multihash)
25+
createWriteStream: (multihash, extension, cb) => {
26+
if (typeof extension === 'function') {
27+
cb = extension
28+
extension = undefined
29+
}
30+
31+
const path = multihashToPath(multihash, extension)
1832
return store.createWriteStream(path, cb)
1933
},
20-
exists: (multihash, cb) => {
21-
const path = multihashToPath(multihash)
34+
exists: (multihash, extension, cb) => {
35+
if (typeof extension === 'function') {
36+
cb = extension
37+
extension = undefined
38+
}
39+
40+
const path = multihashToPath(multihash, extension)
2241
return store.exists(path, cb)
2342
},
24-
remove: (multihash, cb) => {
25-
const path = multihashToPath(multihash)
43+
remove: (multihash, extension, cb) => {
44+
if (typeof extension === 'function') {
45+
cb = extension
46+
extension = undefined
47+
}
48+
49+
const path = multihashToPath(multihash, extension)
2650
return store.remove(path, cb)
2751
}
2852
}
2953
}
30-
31-
function multihashToPath (multihash) {
32-
const filename = multihash.toString('hex') + '.data'
33-
const folder = filename.slice(0, PREFIX_LENGTH)
34-
const path = folder + '/' + filename
35-
36-
return path
37-
}

src/stores/locks.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@ exports.setUp = (basePath, blobStore) => {
88

99
return {
1010
lock: function (cb) {
11-
store.exists(lockFile, doesExist)
11+
function createLock () {
12+
store
13+
.createWriteStream(lockFile)
14+
.on('finish', () => {
15+
cb()
16+
})
17+
.end()
18+
}
1219

1320
function doesExist (err, exists) {
1421
if (err) {
@@ -24,14 +31,7 @@ exports.setUp = (basePath, blobStore) => {
2431
createLock()
2532
}
2633

27-
function createLock () {
28-
store
29-
.createWriteStream(lockFile)
30-
.on('finish', () => {
31-
cb()
32-
})
33-
.end()
34-
}
34+
store.exists(lockFile, doesExist)
3535
},
3636
unlock: (cb) => {
3737
store.remove(lockFile, (err) => {

0 commit comments

Comments
 (0)