Skip to content

Commit 273a141

Browse files
authored
docs: update readmes (#188)
Use ESM in docs and remove references to ipld and replace with blockstores.
1 parent 07f244a commit 273a141

File tree

3 files changed

+38
-34
lines changed

3 files changed

+38
-34
lines changed

packages/ipfs-unixfs-exporter/README.md

+20-18
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
- [Usage](#usage)
2222
- [Example](#example)
2323
- [API](#api)
24-
- [`exporter(cid, ipld, options)`](#exportercid-ipld-options)
24+
- [`exporter(cid, blockstore, options)`](#exportercid-blockstore-options)
2525
- [UnixFSEntry](#unixfsentry)
2626
- [Raw entries](#raw-entries)
2727
- [CBOR entries](#cbor-entries)
2828
- [`entry.content({ offset, length })`](#entrycontent-offset-length-)
29-
- [`walkPath(cid, ipld)`](#walkpathcid-ipld)
30-
- [`recursive(cid, ipld)`](#recursivecid-ipld)
29+
- [`walkPath(cid, blockstore)`](#walkpathcid-blockstore)
30+
- [`recursive(cid, blockstore)`](#recursivecid-blockstore)
3131
- [Contribute](#contribute)
3232
- [License](#license)
3333

@@ -43,21 +43,24 @@
4343

4444
```js
4545
// import a file and export it again
46-
const { importer } = require('ipfs-unixfs-importer')
47-
const { exporter } = require('ipfs-unixfs-exporter')
46+
import { importer } from 'ipfs-unixfs-importer'
47+
import { exporter } from 'ipfs-unixfs-exporter'
48+
import { MemoryBlockstore } from 'blockstore-core/memory'
4849

50+
// Should contain the blocks we are trying to export
51+
const blockstore = new MemoryBlockstore()
4952
const files = []
5053

5154
for await (const file of importer([{
5255
path: '/foo/bar.txt',
5356
content: new Uint8Array([0, 1, 2, 3])
54-
}], ipld)) {
57+
}], blockstore)) {
5558
files.push(file)
5659
}
5760

5861
console.info(files[0].cid) // Qmbaz
5962

60-
const entry = await exporter(files[0].cid, ipld)
63+
const entry = await exporter(files[0].cid, blockstore)
6164

6265
console.info(entry.cid) // Qmqux
6366
console.info(entry.path) // Qmbaz/foo/bar.txt
@@ -80,12 +83,12 @@ console.info(bytes) // 0, 1, 2, 3
8083
#### API
8184

8285
```js
83-
const { exporter } = require('ipfs-unixfs-exporter')
86+
import { exporter } from 'ipfs-unixfs-exporter'
8487
```
8588

86-
### `exporter(cid, ipld, options)`
89+
### `exporter(cid, blockstore, options)`
8790

88-
Uses the given [ipld](https://github.com/ipld/js-ipld) instance to fetch an IPFS node by it's CID.
91+
Uses the given [blockstore][] instance to fetch an IPFS node by it's CID.
8992

9093
Returns a Promise which resolves to a `UnixFSEntry`.
9194

@@ -202,42 +205,41 @@ for await (const entry of dir.content({
202205
// `entries` contains the first 5 files/directories in the directory
203206
```
204207
205-
### `walkPath(cid, ipld)`
208+
### `walkPath(cid, blockstore)`
206209
207210
`walkPath` will return an async iterator that yields entries for all segments in a path:
208211
209212
```javascript
210-
const { walkPath } = require('ipfs-unixfs-exporter')
213+
import { walkPath } from 'ipfs-unixfs-exporter'
211214

212215
const entries = []
213216

214-
for await (const entry of walkPath('Qmfoo/foo/bar/baz.txt', ipld)) {
217+
for await (const entry of walkPath('Qmfoo/foo/bar/baz.txt', blockstore)) {
215218
entries.push(entry)
216219
}
217220

218221
// entries contains 4x `entry` objects
219222
```
220223
221-
### `recursive(cid, ipld)`
224+
### `recursive(cid, blockstore)`
222225
223226
`recursive` will return an async iterator that yields all entries beneath a given CID or IPFS path, as well as the containing directory.
224227
225228
```javascript
226-
const { recursive } = require('ipfs-unixfs-exporter')
229+
import { recursive } from 'ipfs-unixfs-exporter'
227230

228231
const entries = []
229232

230-
for await (const child of recursive('Qmfoo/foo/bar', ipld)) {
233+
for await (const child of recursive('Qmfoo/foo/bar', blockstore)) {
231234
entries.push(entry)
232235
}
233236

234237
// entries contains all children of the `Qmfoo/foo/bar` directory and it's children
235238
```
236239
237240
[dag API]: https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/DAG.md
238-
[ipld-resolver instance]: https://github.com/ipld/js-ipld-resolver
241+
[blockstore]: https://github.com/ipfs/js-ipfs-interfaces/tree/master/packages/interface-blockstore#readme
239242
[UnixFS]: https://github.com/ipfs/specs/tree/master/unixfs
240-
[pull-stream]: https://www.npmjs.com/package/pull-stream
241243
242244
## Contribute
243245

packages/ipfs-unixfs-importer/README.md

+16-14
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
- [Usage](#usage)
1919
- [Example](#example)
2020
- [API](#api)
21-
- [const stream = importer(source, ipld [, options])](#const-stream--importersource-ipld--options)
21+
- [const stream = importer(source, blockstore [, options])](#const-stream--importersource-blockstore--options)
2222
- [Overriding internals](#overriding-internals)
2323
- [Contribute](#contribute)
2424
- [License](#license)
@@ -45,7 +45,11 @@ Let's create a little directory to import:
4545
And write the importing logic:
4646

4747
```js
48-
const { importer } = require('ipfs-unixfs-importer')
48+
import { importer } from 'ipfs-unixfs-importer'
49+
import { MemoryBlockstore } from 'blockstore-core/memory'
50+
51+
// Where the blocks will be stored
52+
const blockstore = new MemoryBlockstore()
4953

5054
// Import path /tmp/foo/bar
5155
const source = [{
@@ -56,9 +60,7 @@ const source = [{
5660
content: fs.createReadStream(file2)
5761
}]
5862

59-
// You need to create and pass an ipld-resolve instance
60-
// https://github.com/ipld/js-ipld-resolver
61-
for await (const entry of importer(source, ipld, options)) {
63+
for await (const entry of importer(source, blockstore, options)) {
6264
console.info(entry)
6365
}
6466
```
@@ -91,10 +93,10 @@ When run, metadata about DAGNodes in the created tree is printed until the root:
9193
#### API
9294

9395
```js
94-
const { importer } = require('ipfs-unixfs-importer')
96+
import { importer } from 'ipfs-unixfs-importer'
9597
```
9698

97-
#### const stream = importer(source, ipld [, options])
99+
#### const stream = importer(source, blockstore [, options])
98100

99101
The `importer` function returns an async iterator takes a source async iterator that yields objects of the form:
100102

@@ -109,9 +111,9 @@ The `importer` function returns an async iterator takes a source async iterator
109111

110112
`stream` will output file info objects as files get stored in IPFS. When stats on a node are emitted they are guaranteed to have been written.
111113

112-
`ipld` is an instance of the [`IPLD Resolver`](https://github.com/ipld/js-ipld-resolver)
114+
`blockstore` is an instance of a [blockstore][]
113115

114-
The input's file paths and directory structure will be preserved in the [`dag-pb`](https://github.com/ipld/js-ipld-dag-pb) created nodes.
116+
The input's file paths and directory structure will be preserved in the [`dag-pb`](https://github.com/ipld/js-dag-pb) created nodes.
115117

116118
`options` is an JavaScript option that might include the following keys:
117119

@@ -150,20 +152,20 @@ Several aspects of the importer are overridable by specifying functions as part
150152
- It should yield `Buffer` objects constructed from the `source` or throw an `Error`
151153
- `chunker` (function): Optional function that supports the signature `async function * (source, options)` where `source` is an async generator and `options` is an options object
152154
- It should yield `Buffer` objects.
153-
- `bufferImporter` (function): Optional function that supports the signature `async function * (entry, ipld, options)`
154-
- This function should read `Buffer`s from `source` and persist them using `ipld.put` or similar
155+
- `bufferImporter` (function): Optional function that supports the signature `async function * (entry, blockstore, options)`
156+
- This function should read `Buffer`s from `source` and persist them using `blockstore.put` or similar
155157
- `entry` is the `{ path, content }` entry, where `entry.content` is an async generator that yields Buffers
156158
- It should yield functions that return a Promise that resolves to an object with the properties `{ cid, unixfs, size }` where `cid` is a [CID], `unixfs` is a [UnixFS] entry and `size` is a `Number` that represents the serialized size of the [IPLD] node that holds the buffer data.
157159
- Values will be pulled from this generator in parallel - the amount of parallelisation is controlled by the `blockWriteConcurrency` option (default: 10)
158-
- `dagBuilder` (function): Optional function that supports the signature `async function * (source, ipld, options)`
160+
- `dagBuilder` (function): Optional function that supports the signature `async function * (source, blockstore, options)`
159161
- This function should read `{ path, content }` entries from `source` and turn them into DAGs
160162
- It should yield a `function` that returns a `Promise` that resolves to `{ cid, path, unixfs, node }` where `cid` is a `CID`, `path` is a string, `unixfs` is a UnixFS entry and `node` is a `DAGNode`.
161163
- Values will be pulled from this generator in parallel - the amount of parallelisation is controlled by the `fileImportConcurrency` option (default: 50)
162-
- `treeBuilder` (function): Optional function that supports the signature `async function * (source, ipld, options)`
164+
- `treeBuilder` (function): Optional function that supports the signature `async function * (source, blockstore, options)`
163165
- This function should read `{ cid, path, unixfs, node }` entries from `source` and place them in a directory structure
164166
- It should yield an object with the properties `{ cid, path, unixfs, size }` where `cid` is a `CID`, `path` is a string, `unixfs` is a UnixFS entry and `size` is a `Number`.
165167

166-
[ipld-resolver instance]: https://github.com/ipld/js-ipld-resolver
168+
[blockstore]: https://github.com/ipfs/js-ipfs-interfaces/tree/master/packages/interface-blockstore#readme
167169
[UnixFS]: https://github.com/ipfs/specs/tree/master/unixfs
168170
[IPLD]: https://github.com/ipld/js-ipld
169171
[CID]: https://github.com/multiformats/js-cid

packages/ipfs-unixfs/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ The UnixFS spec can be found inside the [ipfs/specs repository](http://github.co
4747
### Use in Node.js
4848

4949
```JavaScript
50-
var { UnixFS } = require('ipfs-unixfs')
50+
import { UnixFS } from 'ipfs-unixfs'
5151
```
5252

5353
### Use in a browser with browserify, webpack or any other bundler
5454

5555
The code published to npm that gets loaded on require is in fact a ES5 transpiled version with the right shims added. This means that you can require it and use with your favourite bundler without having to adjust asset management process.
5656

5757
```JavaScript
58-
var { UnixFS } = require('ipfs-unixfs')
58+
import { UnixFS } from 'ipfs-unixfs'
5959
```
6060

6161
### Use in a browser Using a script tag

0 commit comments

Comments
 (0)