Skip to content

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

@2color

Description

@2color

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/NPKXzLw?editors=1010

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugA bug in existing code (including security flaws)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions