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

addFile in @helia/unixfs doesn't respect the path and field and wrapWithDirectory option #707

Open
2color opened this issue Dec 17, 2024 · 0 comments
Labels
kind/bug A bug in existing code (including security flaws)

Comments

@2color
Copy link
Member

2color commented Dec 17, 2024

Bug

When adding a file (with a browser File object) as follows:

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

  // Encode the file with UnixFS
  const cid = await fs.addFile({
    content: file.stream(),
    path: file.name
  }, { wrapWithDirectory: true })

The returned CID is a raw CID and neither path nor wrapWithDirectory are used to wrap the file in a dag-pb UnixFS directory.

Reproduction

https://codepen.io/2color/pen/zxONqPj

Relevant code paths in helia and js-ipfs-unixfs

export async function addFile (file: FileCandidate, blockstore: PutStore, options: Partial<ImporterOptions> = {}): Promise<CID> {
const { cid } = await importFile(file, blockstore, {
...defaultImporterSettings,
...options
})
return cid
}

https://github.com/ipfs/js-ipfs-unixfs/blob/bf060cda444221225675663e2a760ef562437963/packages/ipfs-unixfs-importer/src/index.ts#L383-L391
https://github.com/ipfs/js-ipfs-unixfs/blob/bf060cda444221225675663e2a760ef562437963/packages/ipfs-unixfs-importer/src/index.ts#L383-L391

@2color 2color added the kind/bug A bug in existing code (including security flaws) label Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug A bug in existing code (including security flaws)
Projects
None yet
Development

No branches or pull requests

1 participant