Skip to content

ipfs/js-ipfs-repo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

IPFS Repo JavaScript Implementation

Implementation of the IPFS repo spec (https://github.com/ipfs/specs/tree/master/repo) in JavaScript

Build Status Dependency Status js-standard-style dignified.js

Description

This is the implementation of the IPFS repo spec in JavaScript.

Architecture

┌─────────────────────────────────┐
│ interface defined by Repo Spec  │
├─────────────────────────────────┤
│                                 │                                  ┌──────────────────────┐
│                                 │                                  │ abstract-blob-store  │
│           IPFS REPO             │─────────────────────────────────▶│     interface        │
│                                 │                                  ├──────────────────────┤
│                                 │                                  │      locks           │
└─────────────────────────────────┘                                  └──────────────────────┘
                 │
      ┌──────────┴────┬───────────────┬───────────────┬───────────────┬───────────────┐
      ▼               ▼               ▼               ▼               ▼               ▼
┌───────────┐   ┌───────────┐   ┌───────────┐   ┌───────────┐   ┌───────────┐   ┌───────────┐
│ abstract  │   │ abstract  │   │ abstract  │   │ abstract  │   │ abstract  │   │ abstract  │
│ -blob     │   │ -blob     │   │ -blob     │   │ -blob     │   │ -blob     │   │ -blob     │
│ -store    │   │ -store    │   │ -store    │   │ -store    │   │ -store    │   │ -store    │
│ interface │   │ interface │   │ interface │   │ interface │   │ interface │   │ interface │
├───────────┤   ├───────────┤   ├───────────┤   ├───────────┤   ├───────────┤   ├───────────┤
│           │   │           │   │           │   │           │   │           │   │           │
│   keys    │   │  config   │   │ datastore │   │ datastore │   │   logs    │   │  version  │
│           │   │           │   │           │   │ -legacy   │   │           │   │           │
└───────────┘   └───────────┘   └───────────┘   └───────────┘   └───────────┘   └───────────┘

IPFS repo exposes a well defined interface by the Repo Spec. Each of the individual repos has an interface defined by 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

Usage

var blobStore = require('abstract-blob-store')  // an in-memory blob store
var IPFSRepo = require('js-ipfs-repo')
var repo = new IPFSRepo('/Users/someone/.ipfs', {
  stores: blobStore
})

API

var IPFSRepo = require('ipfs-repo')

var repo = new IPFSRepo(path, opts)

Creates a reference to an IPFS repository at the path path. This does not create the repo, but is an object that refers to the repo at such a path.

Valid keys for opts include:

{
  keys: someBlobStore,
  config: someBlobStore,
  datastore: someBlobStore,
  logs: someBlobStore,
  locks: someBlobStore,
  version: someBlobStore
}

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 cb(err, exists), where exists is true or false.

repo.version.get(cb(err, version))

repo.version.set(version, cb(err))

Read/write the version number of the repository. The version number is the repo version number.

repo.config.get(cb(err, config))

repo.config.set(config, cb(err))

Read/write the configuration object of the repository.

repo.keys

Read/write keys inside the repo. This feature will be expanded once IPRS and KeyChain are finalized and implemented on go-ipfs.

repo.datastore.read(key, cb(err, buffer))

repo.datastore.write(buffer, cb(err, buffer))

Read and write buffers to/from the repo's block store.

repo.datastoreLegacy

WIP

Install

Install via npm:

$ npm i ipfs-repo

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

About

Implementation of the IPFS Repo spec in JavaScript

Resources

License

Unknown and 2 other licenses found

Licenses found

Unknown
LICENSE
Unknown
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published

Contributors 40