-
Notifications
You must be signed in to change notification settings - Fork 106
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
fix: use unixfs exporter to traverse DAGs #455
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c27f637
fix: use unixfs exporter to traverse DAGs
achingbrain 89642e1
Merge branch 'main' into fix/use-unixfs-exporter-to-traverse-hamt
achingbrain d697d8a
chore: expand comment
achingbrain 43d0bca
chore: linting
achingbrain fa47e08
chore: update comment
achingbrain f992160
chore: simplify
achingbrain e9edf81
chore: fix deps
achingbrain File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
import { expect } from 'aegir/chai' | ||
import { MemoryBlockstore } from 'blockstore-core' | ||
import all from 'it-all' | ||
import drain from 'it-drain' | ||
import toBuffer from 'it-to-buffer' | ||
import { unixfs, type UnixFS } from '../src/index.js' | ||
|
@@ -92,4 +93,42 @@ describe('cat', () => { | |
|
||
expect(bytes).to.deep.equal(smallFile) | ||
}) | ||
|
||
it('should only load blocks necessary to traverse a HAMT', async () => { | ||
const [, scriptFile, styleFile, imageFile, dir] = await all(fs.addAll([{ | ||
path: 'index.html', | ||
content: Uint8Array.from([0, 1, 2]) | ||
}, { | ||
path: 'script.js', | ||
content: Uint8Array.from([3, 4, 5]) | ||
}, { | ||
path: 'style.css', | ||
content: Uint8Array.from([6, 7, 8]) | ||
}, { | ||
path: 'image.png', | ||
content: Uint8Array.from([9, 0, 1]) | ||
}], { | ||
shardSplitThresholdBytes: 1, | ||
wrapWithDirectory: true | ||
})) | ||
|
||
const dirStat = await fs.stat(dir.cid) | ||
expect(dirStat.unixfs?.type).to.equal('hamt-sharded-directory') | ||
|
||
// remove all blocks that aren't the index file | ||
await drain(blockstore.deleteMany([ | ||
scriptFile.cid, | ||
styleFile.cid, | ||
imageFile.cid | ||
])) | ||
|
||
// should be able to cat the index file without loading the other files | ||
// in the shard - the blockstore is offline so will throw if requested | ||
// blocks are not present | ||
const bytes = await toBuffer(fs.cat(dir.cid, { | ||
Comment on lines
+125
to
+128
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 see. Nice 👍 |
||
path: 'index.html' | ||
})) | ||
|
||
expect(bytes).to.equalBytes(Uint8Array.from([0, 1, 2])) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is so much cleaner.