You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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)`
* `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.
0 commit comments