-
Notifications
You must be signed in to change notification settings - Fork 71
Add 102 tutorial for CID generation configurations and CID profiles #455
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
236a698
38b9754
a71c65e
bfefafd
c754e86
fb0a578
5cb338d
437ac33
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,3 +15,4 @@ playwright-report | |
| .envrc | ||
| .tool-versions | ||
| .env | ||
| examples/helia-101/2600-h.htm | ||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -0,0 +1,100 @@ | ||||
| import { createReadStream } from 'node:fs' | ||||
| import { globSource, unixfs } from '@helia/unixfs' | ||||
| import { createHelia } from 'helia' | ||||
| import { fixedSize } from 'ipfs-unixfs-importer/chunker' | ||||
| import { balanced } from 'ipfs-unixfs-importer/layout' | ||||
|
|
||||
|
|
||||
| //--------------------------------set up | ||||
|
|
||||
| const helia = await createHelia() | ||||
| const fs = unixfs(helia) | ||||
|
|
||||
| const bigDirectorySource = "https://sourceforge.net/projects/freetype/files/latest/download" | ||||
|
|
||||
| //--------------------------------directory inputs | ||||
|
|
||||
| // using a local copy of https://www.gutenberg.org/files/2600/2600-h/2600-h.htm , curled to this directory but not checked in | ||||
| const bigHtmlFile = createReadStream('./2600-h.htm') | ||||
|
|
||||
| // generate CID according to Helia defaults (~== kubo v1 profile) from bigHtmlFile: | ||||
| const cidBigHTML = await fs.addFile( | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can simplify this by having helia download the file for you as I did in
https://github.com/ipfs-examples/helia-examples/pull/456/files#diff-15db2a7c59c6093dbf74da5c6c0132ad792799c35a93eabe589cf6cd00d1019dR65
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i thought having a local file would simplify the comparison to kubo, since i don't think the latter has a "from URL" option? this is neat, tho, maybe it makes sense to add it as a 5th example before the local-file version to show that it's the same CID between |
||||
| { | ||||
| path: './bigHtmlFile.htm', | ||||
| //content: bigHtmlFile | ||||
| }, { | ||||
| wrapWithDirectory: false | ||||
| } | ||||
| ) | ||||
|
|
||||
| console.log('bigHtmlFile test-cid-v1 profile: ', cidBigHTML.toString()) | ||||
| const stats = await fs.stat(cidBigHTML) | ||||
| console.log('Stats:', stats) | ||||
|
|
||||
| // generate CID according to Kubo legacy-cid-v0 profile from bigHtmlFile: | ||||
| const bigHtmlFile2 = createReadStream('./2600-h.htm') | ||||
| const cidBigHTML2 = await fs.addFile( | ||||
| { | ||||
| path: './bigHtmlFile.htm', | ||||
| //content: bigHtmlFile2 | ||||
| }, { | ||||
| cidVersion: 0, | ||||
| rawLeaves: false, | ||||
| layout: balanced({ | ||||
| maxChildrenPerNode: 174 | ||||
| }), | ||||
| chunker: fixedSize({ | ||||
| chunkSize: 262_144 | ||||
| }), | ||||
| wrapWithDirectory: false | ||||
| } | ||||
| ) | ||||
|
|
||||
| console.log('bigHtmlFile legacy-cid-v0 profile: ', cidBigHTML2.toString()) | ||||
| const stats2 = await fs.stat(cidBigHTML2) | ||||
| console.log('Stats:', stats2) | ||||
|
|
||||
| //--------------------------------directory inputs | ||||
|
|
||||
| // big-directory populated with many small files and subdirectories to trigger | ||||
| // recursive encoding, but not enough to trigger a HAMT-directory | ||||
|
|
||||
| // generate CID according to Helia defaults (~== kubo v1 profile) from a big | ||||
| // directory via the globSource function (see | ||||
| // https://ipfs.github.io/helia/functions/_helia_unixfs.index.globSource.html ): | ||||
|
|
||||
| for await (const entry of fs.addAll(globSource( | ||||
| './big_directory', | ||||
| '**/*' | ||||
| ), { | ||||
| wrapWithDirectory: true | ||||
| } | ||||
| ) | ||||
| ){ | ||||
| console.log('bigDirectory test-cid-v1 profile: ', entry.cid.toString()) | ||||
| const stats3 = await fs.stat(entry.cid) | ||||
| console.log('Stats:', stats3) | ||||
| } | ||||
|
|
||||
| // generate CID according to Kubo legacy-cid-v0 profile from same directory: | ||||
|
|
||||
| for await (const entry of fs.addAll(globSource( | ||||
| './big_directory', | ||||
| '**/*' | ||||
| ), { | ||||
| cidVersion: 0, | ||||
| rawLeaves: false, | ||||
| layout: balanced({ | ||||
| maxChildrenPerNode: 256 | ||||
| }), | ||||
| chunker: fixedSize({ | ||||
| chunkSize: 262_144 | ||||
| }), | ||||
| wrapWithDirectory: true | ||||
| } | ||||
| ) | ||||
| ){ | ||||
| console.log('bigDirectory kubo-cid-v0 profile: ', entry.cid.toString()) | ||||
| const stats4 = await fs.stat(entry.cid) | ||||
| console.log('Stats:', stats4) | ||||
| } | ||||
Uh oh!
There was an error while loading. Please reload this page.