Implementation of the IPFS repo spec (https://github.com/ipfs/specs/tree/master/repo) in JavaScript
This is the implementation of the IPFS repo spec in JavaScript.
Here is the architectural reasoning for this repo:
┌────────────────────────────────────────┐
│ IPFSRepo │
└────────────────────────────────────────┘
┌─────────────────┐
│ / │
├─────────────────┤
│ Datastore │
└─────────────────┘
│
┌───────────┴───────────┐
│ │
┌─────────────────┐ ┌─────────────────┐
│ /blocks │ │ /datastore │
├─────────────────┤ ├─────────────────┤
│ Datastore │ │ LevelDatastore │
└─────────────────┘ └─────────────────┘
┌────────────────────────────────────────┐ ┌────────────────────────────────────────┐
│ IPFSRepo - Default Node.js │ │ IPFSRepo - Default Browser │
└────────────────────────────────────────┘ └────────────────────────────────────────┘
┌─────────────────┐ ┌─────────────────┐
│ / │ │ / │
├─────────────────┤ ├─────────────────┤
│ FsDatastore │ │LevelJSDatastore │
└─────────────────┘ └─────────────────┘
│ │
┌───────────┴───────────┐ ┌───────────┴───────────┐
│ │ │ │
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ /blocks │ │ /datastore │ │ /blocks │ │ /datastore │
├─────────────────┤ ├─────────────────┤ ├─────────────────┤ ├─────────────────┤
│ FlatfsDatastore │ │LevelDBDatastore │ │LevelJSDatastore │ │LevelJSDatastore │
└─────────────────┘ └─────────────────┘ └─────────────────┘ └─────────────────┘
This provides a well defined interface for creating and interacting with an IPFS repo.
> npm install ipfs-repo
var IPFSRepo = require('ipfs-repo')
var IPFSRepo = require('ipfs-repo')
Loading this module through a script tag will make the IpfsRepo
obj available in the global namespace.
<script src="https://unpkg.com/ipfs-repo/dist/index.min.js"></script>
<!-- OR -->
<script src="https://unpkg.com/ipfs-repo/dist/index.js"></script>
Example:
const Repo = require('ipfs-repo')
const repo = new Repo('/tmp/ipfs-repo')
repo.init({ cool: 'config' }, (err) => {
if (err) {
throw err
}
repo.open((err) => {
if (err) {
throw err
}
console.log('repo is ready')
})
})
This now has created the following structure, either on disk or as an in memory representation:
├── blocks
│ ├── SHARDING
│ └── _README
├── config
├── datastore
└── version
See https://ipfs.github.io/js-ipfs-repo
There are some ways you can make this module better:
- Consult our open issues and take on one of them
- Help our tests reach 100% coverage!
This repository falls under the IPFS Code of Conduct.