Skip to content

Commit 85a2810

Browse files
committed
tests: new test repo out of go-ipfs v0.4.10
1 parent a9293e2 commit 85a2810

File tree

38 files changed

+716
-104
lines changed

38 files changed

+716
-104
lines changed

test/test-repo/api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/ip4/127.0.0.1/tcp/5001

test/test-repo/blocks/2F/CIQEUWUVLBXVFYSYCHHSCRTXCYHGIOBXKWUMKFR3UPAFHQ5WK5362FQ.data

Lines changed: 0 additions & 4 deletions
This file was deleted.
Binary file not shown.

test/test-repo/blocks/AE/CIQONICFQZH7QVU6IPSIM3AK7AD554D3BWZPAGEAQYQOWMFZQDUUAEI.data

Lines changed: 0 additions & 3 deletions
This file was deleted.
Binary file not shown.

test/test-repo/blocks/C4/CIQDDZ5EDQK5AP7LRTLZHQZUR2R3GECRFV3WPKNL7PL2SKFIL2LXC4Y.data

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/
2+
" ;)�=֝ޤ\S�jX��aJ�,d��U�U8�+v�direct�T2
3+
" ^��5'��T)�aX��+����L'TZBAJ| recursive�U

test/test-repo/blocks/FN/CIQIXBZMUTXFC5QIGMLJNXLLHZOPGSL2PBC65D4UIVWM6TI5F5TAFNI.data

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 308 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,308 @@
1+
2+
�c�c# IPFS Repo JavaScript Implementation
3+
4+
[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io)
5+
[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)
6+
[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)
7+
[![standard-readme compliant](https://img.shields.io/badge/standard--readme-OK-green.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)
8+
[![Build Status](https://travis-ci.org/ipfs/js-ipfs-repo.svg)](https://travis-ci.org/ipfs/js-ipfs-repo) [![Circle CI](https://circleci.com/gh/ipfs/js-ipfs-repo.svg?style=svg)](https://circleci.com/gh/ipfs/js-ipfs-repo)
9+
[![Coverage Status](https://coveralls.io/repos/github/ipfs/js-ipfs-repo/badge.svg?branch=master)](https://coveralls.io/github/ipfs/js-ipfs-repo?branch=master) [![Dependency Status](https://david-dm.org/diasdavid/js-peer-id.svg?style=flat-square)](https://david-dm.org/ipfs/js-ipfs-repo)
10+
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)
11+
![](https://img.shields.io/badge/npm-%3E%3D3.0.0-orange.svg?style=flat-square)
12+
![](https://img.shields.io/badge/Node.js-%3E%3D4.0.0-orange.svg?style=flat-square)
13+
14+
[![Sauce Test Status](https://saucelabs.com/browser-matrix/ipfs-js-repo.svg)](https://saucelabs.com/u/ipfs-js-repo)
15+
16+
> Implementation of the IPFS repo spec (https://github.com/ipfs/specs/tree/master/repo) in JavaScript
17+
18+
This is the implementation of the [IPFS repo spec](https://github.com/ipfs/specs/tree/master/repo) in JavaScript.
19+
20+
## Table of Contents
21+
22+
- [Background](#background)
23+
- [Install](#install)
24+
- [npm](#npm)
25+
- [Use in Node.js](#use-in-nodejs)
26+
- [Use in a browser with browserify, webpack or any other bundler](#use-in-a-browser-with-browserify-webpack-or-any-other-bundler)
27+
- [Use in a browser Using a script tag](#use-in-a-browser-using-a-script-tag)
28+
- [Usage](#usage)
29+
- [API](#api)
30+
- [Contribute](#contribute)
31+
- [License](#license)
32+
33+
## Background
34+
35+
Here is the architectural reasoning for this repo:
36+
37+
```bash
38+
┌────────────────────────────────────────┐
39+
│ IPFSRepo │
40+
└────────────────────────────────────────┘
41+
┌─────────────────┐
42+
│ / │
43+
├─────────────────┤
44+
│ Datastore │
45+
└─────────────────┘
46+
47+
┌───────────┴───────────┐
48+
│ │
49+
┌─────────────────┐ ┌─────────────────┐
50+
│ /blocks │ │ /datastore │
51+
├─────────────────┤ ├─────────────────┤
52+
│ Datastore │ │ LevelDatastore │
53+
└─────────────────┘ └─────────────────┘
54+
55+
┌────────────────────────────────────────┐ ┌────────────────────────────────────────┐
56+
│ IPFSRepo - Default Node.js │ │ IPFSRepo - Default Browser │
57+
└────────────────────────────────────────┘ └────────────────────────────────────────┘
58+
┌─────────────────┐ ┌─────────────────┐
59+
│ / │ │ / │
60+
├─────────────────┤ ├─────────────────┤
61+
│ FsDatastore │ │LevelJSDatastore │
62+
└─────────────────┘ └─────────────────┘
63+
│ │
64+
┌───────────┴───────────┐ ┌───────────┴───────────┐
65+
│ │ │ │
66+
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
67+
│ /blocks │ │ /datastore │ │ /blocks │ │ /datastore │
68+
├─────────────────┤ ├─────────────────┤ ├─────────────────┤ ├─────────────────┤
69+
│ FlatfsDatastore │ │LevelDBDatastore │ │LevelJSDatastore │ │LevelJSDatastore │
70+
└─────────────────┘ └─────────────────┘ └─────────────────┘ └─────────────────┘
71+
```
72+
73+
This provides a well defined interface for creating and interacting with an IPFS repo.
74+
75+
## Install
76+
77+
### npm
78+
79+
```sh
80+
> npm install ipfs-repo
81+
```
82+
83+
### Use in Node.js
84+
85+
```js
86+
var IPFSRepo = require('ipfs-repo')
87+
```
88+
89+
### Use in a browser with browserify, webpack or any other bundler
90+
91+
```js
92+
var IPFSRepo = require('ipfs-repo')
93+
```
94+
95+
### Use in a browser Using a script tag
96+
97+
Loading this module through a script tag will make the `IpfsRepo` obj available in the global namespace.
98+
99+
```html
100+
<script src="https://unpkg.com/ipfs-repo/dist/index.min.js"></script>
101+
<!-- OR -->
102+
<script src="https://unpkg.com/ipfs-repo/dist/index.js"></script>
103+
```
104+
105+
## Usage
106+
107+
Example:
108+
109+
```js
110+
const Repo = require('ipfs-repo')
111+
const repo = new Repo('/tmp/ipfs-repo')
112+
113+
repo.init({ cool: 'config' }, (err) => {
114+
if (err) {
115+
throw err
116+
}
117+
118+
repo.open((err) => {
119+
if (err) {
120+
throw err
121+
}
122+
123+
console.log('repo is ready')
124+
})
125+
})
126+
```
127+
128+
This now has created the following structure, either on disk or as an in memory representation:
129+
130+
```
131+
├── blocks
132+
│   ├── SHARDING
133+
│ └── _README
134+
├── config
135+
├── datastore
136+
└── version
137+
```
138+
139+
## API
140+
141+
### Setup
142+
143+
#### `new Repo(path[, options])`
144+
145+
Creates an IPFS Repo.
146+
147+
Arguments:
148+
149+
* `path` (string, mandatory): the path for this repo
150+
* `options` (object, optional): may contain the following values
151+
* `lock` (string, defaults to `"fs"` in Node.js, `"memory"` in the browser): what type of lock to use. Lock has to be acquired when opening.
152+
* `storageBackends` (object, optional): may contain the following values, which should each be a class implementing the [datastore interface](https://github.com/ipfs/interface-datastore#readme):
153+
* `root` (defaults to [`datastore-fs`](https://github.com/ipfs/js-datastore-fs#readme) in Node.js and [`datastore-level`](https://github.com/ipfs/js-datastore-level#readme) in the browser). Defines the back-end type used for gets and puts of values at the root (`repo.set()`, `repo.get()`)
154+
* `blocks` (defaults to [`datastore-fs`](https://github.com/ipfs/js-datastore-fs#readme) in Node.js and [`datastore-level`](https://github.com/ipfs/js-datastore-level#readme) in the browser). Defines the back-end type used for gets and puts of values at `repo.blocks`.
155+
* `datastore` (defaults to [`datastore-level`](https://github.com/ipfs/js-datastore-level#readme)). Defines the back-end type used as the key-valye store used for gets and puts of values at `repo.datastore`.
156+
157+
```js
158+
const repo = new Repo('path/to/repo')
159+
```
160+
161+
#### `repo.init (callback)`
162+
163+
Creates the necessary folder structure inside the repo.
164+
165+
#### `repo.open (callback)`
166+
167+
Locks the repo.
168+
169+
#### `repo.close (callback)`
170+
171+
Unlocks the repo.
172+
173+
#### `repo.exists (callback)`
174+
175+
Tells whether this repo exists or not. Calls back with `(err, bool)`.
176+
177+
### Repos
178+
179+
Root repo:
180+
181+
#### `repo.put (key, value:Buffer, callback)`
182+
183+
Put a value at the root of the repo.
184+
185+
* `key` can be a buffer, a string or a [Key](https://github.com/ipfs/interface-datastore#keys).
186+
187+
#### `repo.get (key, callback)`
188+
189+
Get a value at the root of the repo.
190+
191+
* `key` can be a buffer, a string or a [Key](https://github.com/ipfs/interface-datastore#keys).
192+
* `callback` is a callback function `function (err, result:Buffer)`
193+
194+
[Blocks](https://github.com/ipfs/js-ipfs-block#readme):
195+
196+
#### `repo.blocks.put (block:Block, callback)`
197+
198+
* `block` should be of type [Block](https://github.com/ipfs/js-ipfs-block#readme).
199+
200+
#### `repo.blocks.putMany (blocks, callback)`
201+
202+
Put many blocks.
203+
204+
* `block` should be an array of type [Block](https://github.com/ipfs/js-ipfs-block#readme).
205+
206+
#### `repo.blocks.get (cid, callback)`
207+
208+
Get block.
209+
210+
* `cid` is the content id of [type CID](https://github.com/ipld/js-cid#readme).
211+
* `callback` is a callback function `function (err, result:Buffer)`
212+
213+
Datastore:
214+
215+
#### `repo.datastore`
216+
217+
This is contains a full implementation of [the `interface-datastore` API](https://github.com/ipfs/interface-datastore#api).
218+
219+
220+
### Utils
221+
222+
#### `repo.config`
223+
224+
Instead of using `repo.set('config')` this exposes an API that allows you to set and get a decoded config object, as well as, in a safe manner, change any of the config values individually.
225+
226+
##### `repo.config.set(key:string, value, callback)`
227+
228+
Set a config value. `value` can be any object that is serializable to JSON.
229+
230+
* `key` is a string specifying the object path. Example:
231+
232+
```js
233+
repo.config.set('a.b.c', 'c value', (err) => {
234+
if (err) { throw err }
235+
repo.config.get((err, config) => {
236+
if (err) { throw err }
237+
assert.equal(config.a.b.c, 'c value')
238+
})
239+
})
240+
```
241+
242+
##### `repo.config.get(value, callback)`
243+
244+
Set the whole config value. `value` can be any object that is serializable to JSON.
245+
246+
##### `repo.config.get(key:string, callback)`
247+
248+
Get a config value. `callback` is a function with the signature: `function (err, value)`, wehre the `
249+
value` is of the same type that was set before.
250+
251+
* `key` is a string specifying the object path. Example:
252+
253+
```js
254+
repo.config.get('a.b.c', (err, value) => {
255+
if (err) { throw err }
256+
console.log('config.a.b.c = ', value)
257+
})
258+
```
259+
260+
##### `repo.config.get(callback)`
261+
262+
Get the entire config value. `callback` is a function with the signature: `function (err, configValue:Object)`.
263+
264+
#### `repo.config.exists(callback)`
265+
266+
Whether the config sub-repo exists. Calls back with `(err, bool)`.
267+
268+
#### `repo.version`
269+
270+
##### `repo.version.get (callback)`
271+
272+
Gets the repo version.
273+
274+
##### `repo.version.set (version:number, callback)`
275+
276+
Sets the repo version
277+
278+
#### `repo.apiAddr`
279+
280+
#### `repo.apiAddr.get (callback)`
281+
282+
Gets the API address.
283+
284+
#### `repo.apiAddr.set (value, callback)`
285+
286+
Sets the API address.
287+
288+
* `value` should be a [Multiaddr](https://github.com/multiformats/js-multiaddr) or a String representing a valid one.
289+
290+
## Notes
291+
292+
- [Explanation of how repo is structured](https://github.com/ipfs/js-ipfs-repo/pull/111#issuecomment-279948247)
293+
294+
## Contribute
295+
296+
There are some ways you can make this module better:
297+
298+
- Consult our [open issues](https://github.com/ipfs/js-ipfs-repo/issues) and take on one of them
299+
- Help our tests reach 100% coverage!
300+
301+
This repository falls under the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).
302+
303+
[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/contributing.md)
304+
305+
## License
306+
307+
[MIT](LICENSE)
308+
�c

test/test-repo/blocks/GQ/CIQH7OEYWXL34RWYL7VXLWEU4FWPVGT24VJT7DUZPTNLF25N25IGGQA.data

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)