Skip to content

Commit 5a38d01

Browse files
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 more
1 parent 9a191d2 commit 5a38d01

File tree

99 files changed

+2661
-4201
lines changed

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

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ dist
66
node_modules
77
package-lock.json
88
yarn.lock
9+
.vscode

Diff for: package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@
2929
"clean": "aegir run clean",
3030
"build": "aegir run build",
3131
"lint": "aegir run lint",
32+
"generate": "aegir run generate",
3233
"docs": "NODE_OPTIONS=--max_old_space_size=4096 aegir docs",
3334
"docs:no-publish": "npm run docs -- --publish false",
3435
"dep-check": "aegir run dep-check",
3536
"release": "npm run docs:no-publish && aegir run release && npm run docs"
3637
},
37-
"dependencies": {
38+
"devDependencies": {
3839
"aegir": "^38.1.2"
3940
},
4041
"workspaces": [

Diff for: packages/ipfs-unixfs-exporter/package.json

+2-18
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,6 @@
2020
},
2121
"type": "module",
2222
"types": "./dist/src/index.d.ts",
23-
"typesVersions": {
24-
"*": {
25-
"*": [
26-
"*",
27-
"dist/*",
28-
"dist/src/*",
29-
"dist/src/*/index"
30-
],
31-
"src/*": [
32-
"*",
33-
"dist/*",
34-
"dist/src/*",
35-
"dist/src/*/index"
36-
]
37-
}
38-
},
3923
"files": [
4024
"src",
4125
"dist",
@@ -45,7 +29,7 @@
4529
"exports": {
4630
".": {
4731
"types": "./dist/src/index.d.ts",
48-
"import": "./src/index.js"
32+
"import": "./dist/src/index.js"
4933
}
5034
},
5135
"eslintConfig": {
@@ -183,6 +167,6 @@
183167
"fs": false
184168
},
185169
"typedoc": {
186-
"entryPoint": "./src/index.js"
170+
"entryPoint": "./src/index.ts"
187171
}
188172
}

Diff for: packages/ipfs-unixfs-exporter/src/index.js

-151
This file was deleted.

0 commit comments

Comments
 (0)