js-ipfs-repo

Implementation of the IPFS repo spec (https://github.com/ipfs/specs/tree/master/repo) in JavaScript
API
Repo
Constructor, accepts a path and options:
var Repo = require('js-ipfs-repo')
var repo = new Repo('/Users/someone/.ipfs', {adaptor: 'fs'})
Options:
adaptor
: String with the adaptor. Defaults to fs
version
Read/Write the version number of that repository.
repo.version.read(function (err, num) {
console.log(err, num)
})
repo.version.write(3, function (err) {
console.log(err)
})
api
Read/Write the JSON configuration for that repository.
repo.api.read(function (err, multiaddr) {
console.log(err, multiaddr)
})
repo.api.write('/ip4/127.0.0.1/tcp/5001', function (err) {
console.log(err)
})
config
Read/Write the JSON configuration for that repository.
repo.config.read(function (err, json) {
console.log(err, json)
})
repo.config.write({foo: 'bar'}, function (err) {
console.log(err)
})
blocks
Store data on the block store.
repo.blocks.read('12200007d4e3a319cd8c7c9979280e150fc5dbaae1ce54e790f84ae5fd3c3c1a0475', function (err, buff) {
console.log(err)
})
repo.blocks.write(buff, function (err, buffer) {
console.log(buff.toString('utf-8'), err)
})
repo
Read/Write the repo.lock
file.
repo.repo.read(function (err, content) {
console.log(err, content)
})
repo.repo.write('foo', function (err) {
console.log(err)
})
Adaptors
By default it will use the fs-repo
adaptor. Eventually we can write other adaptors
and make those available on configuration.
fs-repo
The default adaptor. Uses the repo.lock
file to ensure there are no simultaneous reads
nor writes. Uses the fs-blob-store
.
memory-repo
Ideal for testing purposes. Uses the abstract-blob-store
.
Tests
Help us make more tests! Also, enabling them to be run in Node.js and the Browser.