Commit 5a38d01
authored
feat!: accept pre-configured import components as options instead of options for components (#283)
The existing importer takes one big options object that contains options for every subsystem. This leads to situations where different components use the same option keys - for example both the rabin and fixed-size chunkers use the `maxChunkSize` key.
This PR reduces the number of options by accepting preconfigured instances of internal components - e.g. instead of passing `'"rabin"` for the chunker argument, you pass an instance of the rabin chunker instead. This greatly simplifies the config and also allows a simple way for users to pass custom chunkers in. The same thing applies to file layouts, dag builders etc.
Before:
```js
import { importer } from 'ipfs-unixfs-importer'
for await (const result of importer(stream, blockstore, {
chunker: 'rabin',
avgChunkSize: 512000,
strategy: 'trickle'
}) {
// ...
}
```
After:
```js
import { importer } from 'ipfs-unixfs-importer'
import { rabin } from 'ipfs-unixfs-importer/chunkers'
import { trickle } from 'ipfs-unixfs-importer/layouts'
for await (const result of importer(stream, blockstore, {
chunker: rabin({
avgChunkSize: 512000
}),
layout: trickle()
}) {
// ...
}
```
Other breaking changes:
- This module is now typescript
- CID 1 is now the default
- Raw leaves: true is now the default
- The `onlyHash` option has been removed - just pass a `MemoryBlockstore` or other blockstore implementation that doesn't store the blocks anywhere
- The `strategy` config key is now `layout` and accepts an instance of a file layout instead of a string
- The `chunker` config key now accepts an instance of a file chunker instead of a string
`importContent`, `importBytes` and `importByteStream` functions are also now exported along side `importer` to make dealing with simple imports that only import one thing easier.
```js
import { importContent, importBytes, importByteStream } from 'ipfs-unixfs-importer'
// import single file/directory
const result = await importContent({
path: 'foo.txt',
content: Uint8Array.from([0, 1, 2, 3, 4])
}, blockstore, options)
// import single buffer
const result = await importBytes(Uint8Array.from([0, 1, 2, 3, 4]), blockstore, options)
// import single byte stream
const result = await importByteStream(fs.createReadStream('./foo.txt'), blockstore, options)
```
BREAKING CHANGE: The options object now accepts preconfigured instances of chunkers and file layouts - these can be imported from this module - see #283 for more1 parent 9a191d2 commit 5a38d01
File tree
99 files changed
+2661
-4201
lines changed- packages
- ipfs-unixfs-exporter
- src
- resolvers
- unixfs-v1
- content
- utils
- test
- helpers
- ipfs-unixfs-importer
- src
- chunker
- dag-builder
- file
- layout
- utils
- test
- helpers
- ipfs-unixfs
- src
- test
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
99 files changed
+2661
-4201
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
37 | | - | |
| 38 | + | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | 23 | | |
40 | 24 | | |
41 | 25 | | |
| |||
45 | 29 | | |
46 | 30 | | |
47 | 31 | | |
48 | | - | |
| 32 | + | |
49 | 33 | | |
50 | 34 | | |
51 | 35 | | |
| |||
183 | 167 | | |
184 | 168 | | |
185 | 169 | | |
186 | | - | |
| 170 | + | |
187 | 171 | | |
188 | 172 | | |
This file was deleted.
0 commit comments