Skip to content
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

Helia UnixFs addFile does not respect wrapWithDirectory #506

Open
2color opened this issue Apr 19, 2024 · 3 comments
Open

Helia UnixFs addFile does not respect wrapWithDirectory #506

2color opened this issue Apr 19, 2024 · 3 comments

Comments

@2color
Copy link
Member

2color commented Apr 19, 2024

Given the following code:

const helia = await createHelia()
const fs = unixfs(helia)

const cid = await fs.addFile({
  path: 'index.html',
  content: Uint8Array.from([4, 3, 2, 1])
}, {
  wrapWithDirectory: true
})

console.log(cid) // CID(bafkreihocdnev37gdi356hposn6kgiq27i5sgupz5i2o3o5xnfltyz4f64)

The fs.addFile returns a raw CID (bafkreihocdnev37gdi356hposn6kgiq27i5sgupz5i2o3o5xnfltyz4f64 and does not wrap the added file in a directory.

@2color
Copy link
Member Author

2color commented Apr 19, 2024

It seems that this is also the case for fs.addBytes which doesn't respect wrapWithDirectory

@2color
Copy link
Member Author

2color commented Apr 23, 2024

From @achingbrain

I’m not sure, I think maybe? The method is addFile, which it does, but if we don’t return a directory wrapper the filename is ignored.
Since we’re accepting wrapWithDirectory, we should honour that and return the CID for the directory.
Should we do this anyway if a path is supplied?
What about a deeply nested path?

I guess the most obvious thing to do is to:

  • wrap the output in a directory if wrapWithDirectory is passed
  • wrap the output in a directory if a path is passed
  • deeply nest the output if a deeply nested path is passed

What if we pass a nested path and wrapWithDirectory? Do we ignore wrapWith.. since the returned CID would be the outermost directory anyway?

@2color
Copy link
Member Author

2color commented Apr 23, 2024

Since we’re accepting wrapWithDirectory, we should honour that and return the CID for the directory.

👍

I guess the most obvious thing to do is to:

  • wrap the output in a directory if wrapWithDirectory is passed
  • wrap the output in a directory if a path is passed
  • deeply nest the output if a deeply nested path is passed

Makes sense to me

What if we pass a nested path and wrapWithDirectory? Do we ignore wrapWith.. since the returned CID would be the outermost directory anyway?

Also makes sense to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant