This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Refactor refs-local to not use ipfs.add #2980
Closed
Closed
Conversation
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
I believe I'm very close but just need some guidance on how to properly structure the Expected root hash: |
The second file. it('should get local refs', async function () {
const createFile = async (data, chunkSize = 262144) => {
let chunks = []
for (let i = 0; i < data.length; i += chunkSize) {
const unixfs = new UnixFS({
type: 'file',
data: data.slice(i, i + chunkSize)
})
const dagNode = new DAGNode(unixfs.marshal())
const block = await ipfs.block.put(dagNode.serialize())
chunks.push({
unixfs,
size: block.data.length,
cid: block.cid
})
}
if (chunks.length === 1) {
return {
cid: chunks[0].cid,
cumulativeSize: chunks[0].size
}
}
const unixfs = new UnixFS({
type: 'file',
blockSizes: chunks.map(chunk => chunk.unixfs.fileSize())
})
const dagNode = new DAGNode(unixfs.marshal(), chunks.map(chunk => new DAGLink('', chunk.size, chunk.cid)))
const block = await ipfs.block.put(dagNode.serialize())
return {
cid: block.cid,
cumulativeSize: chunks.reduce((acc, curr) => acc + curr.size, 0) + block.data.length
}
}
const pp = await createFile(fixtures.directory.files['pp.txt'])
const holmes = await createFile(fixtures.directory.files['holmes.txt'])
const directory = new UnixFS({ type: 'directory' })
const serialized = new DAGNode(directory.marshal(), [
new DAGLink('pp.txt', pp.cumulativeSize, pp.cid),
new DAGLink('holmes.txt', holmes.cumulativeSize, holmes.cid)
]).serialize()
await ipfs.block.put(serialized)
const refs = await all(ipfs.refs.local())
const cids = refs.map(r => r.ref)
expect(cids).to.include('QmVwdDCY4SPGVFnNCiZnX5CtzwWDn6kAM98JXzKxE3kCmn')
expect(cids).to.include('QmR4nFjTu18TyANgC65ArNWp5Yaab1gPzQ4D8zp7Kx3vhr')
}) Probably want to put the |
Update refs-local.js feat: createFile method from @achingbrain fix: linting
@achingbrain much better, thank you for the help |
This was referenced Apr 15, 2020
I believe the errors here and in #2982 appear to be unrelated to the changeset in the PRs |
This was referenced Apr 17, 2020
achingbrain
added a commit
that referenced
this pull request
Apr 24, 2020
Follows on from #2980 but uses the unixfs-importer which has been refactored to only use the block API, allowing implementations to be written from low-level APIs upwards.
achingbrain
added a commit
that referenced
this pull request
Apr 24, 2020
Follows on from #2980 but uses the unixfs-importer which has been refactored to only use the block API, allowing implementations to be written from low-level APIs upwards.
I've opened #3005 which accomplishes the same thing, but uses less code :) |
Go ahead and close this if it works for you! |
Fixed in #3005 |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
This PR refactors
ipfs.add
away from the refs-local test, relying instead on the more basicblock.put
. This is based on the need foripfs-rust/rust-ipfs
to work through the conformance testing in the order planned in the dev grant.Basing this work off of the techniques used in #2972