ipfs-repo
0.18.7

Intro

Installable via npm install --save ipfs-repo, it can also be used directly in the browser.

Quick Example

'use strict'

const Repo = require('ipfs-repo')
const repo = new Repo('/Users/awesome/.jsipfs')

repo.init({my: 'config'}, (err) => {
  if (err) {
    throw err
  }

  repo.open((err) => {
    if (err) {
      throw err
    }

    console.log('repo is ready')
  })
})

There are more available, so take a look at the docs below for a full list. This documentation aims to be comprehensive, so if you feel anything is missing please create a GitHub issue for it.

Download

The source is available for download from GitHub. Alternatively, you can install using npm:

$ npm install --save ipfs-repo

You can then require() ipfs-repo as normal:

const ipfsRepo = require('ipfs-repo')

In the Browser

Ipfs-repo should work in any ES2015 environment out of the box.

Usage:

<script type="text/javascript" src="index.js"></script>

The portable versions of ipfs-repo, including index.js and index.min.js, are included in the /dist folder. Ipfs-repo can also be found on unkpkg.com under

get

Get the current configuration from the repo.

Parameters

  1. callback: function (Error, Object):  

Returns

void

get

Get a single block by CID.

Parameters

  1. cid: CID:  
  2. callback: function (Error, Block):  

Returns

void

get

Get the current version.

Parameters

  1. callback: function (Error, number):  

Returns

void

set

Set the current configuration for this repo.

Parameters

  1. value: Object:  
    the api address to be written
  2. callback: function (Error):  

Returns

void

set

Set the version of the repo, writing it to the underlying store.

Parameters

  1. version: number:  
  2. callback: function (Error):  

Returns

void

delete

Deletes api file

Parameters

  1. callback: function (Error, bool):  

Returns

void

delete

Delete a block from the store

Parameters

  1. cid: CID:  
  2. callback: function (Error):  

Returns

void

keyFromBuffer

Transform a raw buffer to a base32 encoded key.

Parameters

  1. rawKey: Buffer:  

Returns

Key

cidToDsKey

Transform a cid to the appropriate datastore key.

Parameters

  1. cid: CID:  

Returns

Key

query

Query the store.

Parameters

  1. query: object:  
  2. callback: function (Error, Array):  

Returns

void

putMany

Like put, but for more.

Parameters

  1. blocks: Array<Block>:  
  2. callback: function (Error):  

Returns

void

has

Does the store contain block with this cid?

Parameters

  1. cid: CID:  
  2. callback: function (Error, bool):  

Returns

void

get

Get the current configuration from the repo.

Parameters

  1. key: String:  
    the config key to get
  2. callback: function (Error, Object):  

Returns

void

set

Set the current configuration for this repo.

Parameters

  1. key: String:  
    the config key to be written
  2. value: Object:  
    the config value to be written
  3. callback: function (Error):  

Returns

void

exists

Check if a config file exists.

Parameters

  1. callback: function (Error, bool):  

Returns

void

IpfsRepo

IpfsRepo implements all required functionality to read and write to an ipfs repo.

Parameters

  1. repoPath: any:  
  2. options: any:  

instance

IpfsRepo.prototype.init

init(config: Object, callback: function (Error)): void

Initialize a new repo.

Parameters

  1. config: Object:  
    config to write into config .
  2. callback: function (Error):  

Returns

void

IpfsRepo.prototype.open

open(callback: function (Error)): void

Open the repo. If the repo is already open no action will be taken. If the repo is not initialized it will return an error.

Parameters

  1. callback: function (Error):  

Returns

void

IpfsRepo.prototype.close

close(callback: function (Error)): void

Close the repo and cleanup.

Parameters

  1. callback: function (Error):  

Returns

void

IpfsRepo.prototype.exists

exists(callback: function (Error, bool)): void

Check if a repo exists.

Parameters

  1. callback: function (Error, bool):  

Returns

void

IpfsRepo.prototype.stat

stat(options: Object, callback: function (Error, Object)): void

Get repo status.

Parameters

  1. options: Object:  
  2. options.human: Boolean:  
  3. callback: function (Error, Object):  

Returns

void

lock

Lock the repo in the given dir.

Parameters

  1. dir: string:  
  2. callback: function (Error, lock):  

Returns

void

locked

Check if the repo in the given directory is locked.

Parameters

  1. dir: string:  
  2. callback: function (Error, bool):  

Returns

void

exists

Check if a version file exists.

Parameters

  1. callback: function (Error, bool):  

Returns

void

check

Check the current version, and return an error on missmatch

Parameters

  1. expected: number:  
  2. callback: function (Error):  

Returns

void