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
{{ message }}
This repository was archived by the owner on Apr 29, 2020. It is now read-only.
feat: allow overriding of internal functions (#48)
* feat: allow overriding of internal functions
The interesting bits of this module are the various ways of building
DAGs for files and folders (flat, sharded, etc).
Sometimes we want to utilise bits of this logic to build DAGs without
having to reimplement big chunks of this module.
This PR allows the user to pass in functions to replace key parts of
this import pipeline.
Enables:
* ipfs-inactive/js-ipfs-mfs#73
* #46
* docs: add description about internal funcs
@@ -145,8 +146,32 @@ The input's file paths and directory structure will be preserved in the [`dag-pb
145
146
-`blockWriteConcurrency` (positive integer, defaults to 10) How many blocks to hash and write to the block store concurrently. For small numbers of large files this should be high (e.g. 50).
146
147
-`fileImportConcurrency` (number, defaults to 50) How many files to import concurrently. For large numbers of small files this should be high (e.g. 50).
147
148
149
+
## Overriding internals
150
+
151
+
Several aspects of the importer are overridable by specifying functions as part of the options object with these keys:
152
+
153
+
-`chunkValidator` (function): Optional function that supports the signature `async function * (source, options)`
154
+
- This function takes input from the `content` field of imported entries. It should transform them into `Buffer`s, throwing an error if it cannot.
155
+
- It should yield `Buffer` objects constructed from the `source` or throw an `Error`
156
+
-`chunker` (function): Optional function that supports the signature `async function * (source, options)` where `source` is an async generator and `options` is an options object
157
+
- It should yield `Buffer` objects.
158
+
-`bufferImporter` (function): Optional function that supports the signature `async function * (entry, source, ipld, options)`
159
+
- This function should read `Buffer`s from `source` and persist them using `ipld.put` or similar
160
+
-`entry` is the `{ path, content }` entry, `source` is an async generator that yields Buffers
161
+
- 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.
162
+
- Values will be pulled from this generator in parallel - the amount of parallelisation is controlled by the `blockWriteConcurrency` option (default: 10)
163
+
-`dagBuilder` (function): Optional function that supports the signature `async function * (source, ipld, options)`
164
+
- This function should read `{ path, content }` entries from `source` and turn them into DAGs
165
+
- 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`.
166
+
- Values will be pulled from this generator in parallel - the amount of parallelisation is controlled by the `fileImportConcurrency` option (default: 50)
167
+
-`treeBuilder` (function): Optional function that supports the signature `async function * (source, ipld, options)`
168
+
- This function should read `{ cid, path, unixfs, node }` entries from `source` and place them in a directory structure
169
+
- 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`.
0 commit comments