diff --git a/README.md b/README.md
index c1c0a649..fa8a7627 100644
--- a/README.md
+++ b/README.md
@@ -41,7 +41,12 @@ This is the implementation of the [IPFS repo spec](https://github.com/ipfs/specs
└───────────┘ └───────────┘ └───────────┘ └───────────┘ └───────────┘ └───────────┘
```
-IPFS repo exposes a well defined interface by the Repo Spec. Each of the individual repos has an interface defined by [abstract-blob-store](https://github.com/maxogden/abstract-blob-store), this enables us to make IPFS repo portable (running on Node.js vs the browser) and accept different types of storage mechanisms for each repo (fs, levelDB, etc).
+This provides a well defined interface for creating and interacting with an IPFS
+Repo backed by a group of abstract backends for keys, configuration, logs, and
+more. Each of the individual repos has an interface defined by
+[abstract-blob-store](https://github.com/maxogden/abstract-blob-store): this
+enables us to make IPFS Repo portable (running on Node.js vs the browser) and
+accept different types of storage mechanisms for each repo (fs, levelDB, etc).
## Good to know (historical context)
@@ -49,40 +54,7 @@ IPFS repo exposes a well defined interface by the Repo Spec. Each of the individ
- The blocks folder is the current version of datastore.
- The keys repo doesn't exist yet, as the private key is simply stored inside config
-# Installation
-
-## npm
-
-```sh
-> npm i ipfs-repo
-```
-
-## Use in Node.js
-
-```JavaScript
-var IPFSRepo = require('ipfs-repo')
-```
-
-## Use in a browser with browserify, webpack or any other bundler
-
-The code published to npm that gets loaded on require is in fact a ES5 transpiled version with the right shims added. This means that you can require it and use with your favourite bundler without having to adjust asset management process.
-
-```JavaScript
-var IPFSRepo = require('ipfs-repo')
-```
-
-## Use in a browser Using a script tag
-
-Loading this module through a script tag will make the `Unixfs` obj available in the global namespace.
-
-```html
-
-
-
-```
-
-
-# Usage
+# Example
```js
var fsBlobStore = require('fs-blob-store') // an in-memory blob store
@@ -122,12 +94,6 @@ Valid keys for `opts` include:
If you use the former form, all of the sub-blob-stores will use the same store.
-### repo.init(config, cb)
-
-Initializes the IPFS repository at the repo's `path`. Currently this is a no-op.
-
-Consumes a config object `config` *(TODO: specification?)* By default, init requires the repo not yet exist (by default). Calls the callback `cb(err)` on completion or error.
-
### repo.exists(cb)
Check if the repo you are going to access already exists. Calls the callback
@@ -158,18 +124,42 @@ Read and write buffers to/from the repo's block store.
**WIP**
-## Install
+# Installation
-Install via npm:
+## npm
-```bash
-$ npm i ipfs-repo
+```sh
+> npm i ipfs-repo
+```
+
+## Use in Node.js
+
+```JavaScript
+var IPFSRepo = require('ipfs-repo')
+```
+
+## Use in a browser with browserify, webpack or any other bundler
+
+The code published to npm that gets loaded on require is in fact a ES5 transpiled version with the right shims added. This means that you can require it and use with your favourite bundler without having to adjust asset management process.
+
+```JavaScript
+var IPFSRepo = require('ipfs-repo')
+```
+
+## Use in a browser Using a script tag
+
+Loading this module through a script tag will make the `Unixfs` obj available in the global namespace.
+
+```html
+
+
+
```
## Contribute
There are some ways you can make this module better:
-- Consult our open issues and take on one of them
-- Make the tests better
-- Make the tests work in the Browser
+- Consult our [open issues](https://github.com/ipfs/js-ipfs-repo/issues) and take on one of them
+- Help our tests reach 100% coverage!
+
diff --git a/package.json b/package.json
index 5e039c0e..5da4eef2 100644
--- a/package.json
+++ b/package.json
@@ -29,6 +29,7 @@
],
"homepage": "https://github.com/ipfs/js-ipfs-repo",
"devDependencies": {
+ "abstract-blob-store": "^3.2.0",
"aegir": "^2.1.1",
"async": "^1.5.2",
"bl": "^1.1.2",
diff --git a/src/index.js b/src/index.js
index e1033742..e481fe70 100644
--- a/src/index.js
+++ b/src/index.js
@@ -3,6 +3,9 @@
const stores = require('./stores')
function Repo (repoPath, options) {
+ if (!(this instanceof Repo)) {
+ return new Repo(repoPath, options)
+ }
if (!options) { throw new Error('missing options param') }
if (!options.stores) { throw new Error('missing options.stores param') }
@@ -22,14 +25,6 @@ function Repo (repoPath, options) {
this.path = repoPath
- this.init = (config, callback) => {
- this.exists((err, exists) => {
- if (err) { throw err }
- if (exists) { throw new Error('Repo already exists') }
- throw new Error('not implemented')
- })
- }
-
this.locks = stores
.locks
.setUp(repoPath, options.stores.locks)
@@ -59,16 +54,6 @@ function Repo (repoPath, options) {
this.datastore = stores
.datastore
.setUp(repoPath, options.stores.datastore, this.locks)
-
- // TODO: needs https://github.com/ipfs/js-ipfs-repo/issues/6#issuecomment-164650642
- // this.datastoreLegacy = stores
- // .datastore
- // .setUp(repoPath, options.stores.datastore, this.locks)
-
- // TODO: Currently this was also deprecated in go-ipfs
- // this.logs = stores
- // .logs
- // .setUp(repoPath, options.stores.logs, this.locks)
}
exports = module.exports = Repo
diff --git a/test/repo-test.js b/test/repo-test.js
index e332442c..97dd9db0 100644
--- a/test/repo-test.js
+++ b/test/repo-test.js
@@ -2,6 +2,7 @@
'use strict'
+const Repo = require('../src/index')
const expect = require('chai').expect
const base58 = require('bs58')
const bl = require('bl')
@@ -14,6 +15,32 @@ const fileAExt = fs.readFileSync(join(__dirname, 'test-repo/blocks/12207028/1220
module.exports = function (repo) {
describe('IPFS Repo Tests', function () {
+ it('can init repo /wo new', (done) => {
+ var repo
+ function run () {
+ repo = Repo('foo', { stores: require('abstract-blob-store') })
+ }
+ expect(run).to.not.throw(Error)
+ expect(repo).to.be.an.instanceof(Repo)
+ done()
+ })
+
+ it('bad repo init 1', (done) => {
+ function run () {
+ return new Repo()
+ }
+ expect(run).to.throw(Error)
+ done()
+ })
+
+ it('bad repo init 2', (done) => {
+ function run () {
+ return new Repo('', {})
+ }
+ expect(run).to.throw(Error)
+ done()
+ })
+
it('check if Repo exists', (done) => {
repo.exists((err, exists) => {
expect(err).to.not.exist