Skip to content

Commit

Permalink
Merge pull request #46 from noffle/coverage-and-readme
Browse files Browse the repository at this point in the history
Code cleanup, better coverage, readme improvements
  • Loading branch information
daviddias committed Apr 22, 2016
2 parents 17e38bc + 7544d2a commit a8ce3a6
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 66 deletions.
86 changes: 38 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,48 +41,20 @@ 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)

- The datastore folder holds the legacy version of datastore, still built in levelDB, there is a current endeavour of pushing it to fs completely.
- 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
<script src="https://npmcdn.com/ipfs-repo/dist/index.min.js"></script>
<!-- OR -->
<script src="https://npmcdn.com/ipfs-repo/dist/index.js"></script>
```


# Usage
# Example

```js
var fsBlobStore = require('fs-blob-store') // an in-memory blob store
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
<script src="https://npmcdn.com/ipfs-repo/dist/index.min.js"></script>
<!-- OR -->
<script src="https://npmcdn.com/ipfs-repo/dist/index.js"></script>
```

## 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!

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
21 changes: 3 additions & 18 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') }

Expand All @@ -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)
Expand Down Expand Up @@ -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
27 changes: 27 additions & 0 deletions test/repo-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

'use strict'

const Repo = require('../src/index')
const expect = require('chai').expect
const base58 = require('bs58')
const bl = require('bl')
Expand All @@ -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
Expand Down

0 comments on commit a8ce3a6

Please sign in to comment.