Skip to content

Wrap with directory option with uint8array data returns empty root CID #176

Open
@vasco-santos

Description

@vasco-santos

Code snipped replicating the issue:

import IPFS from 'ipfs-core'

const ipfs = await IPFS.create()
const { cid } = await ipfs.add(new Uint8Array([1, 2, 3]), {
  cidVersion: 1,
  wrapWithDirectory: true
})
console.info(cid) // CID(bafybeiczsscdsbs7ffqz55asqdf3smv6klcw3gofszvwlyarci47bgf354)

The expectation would be to either throw an error or wrap with a directory. From my debugging, it looks that the underlying reason for this is that a path is not provided and unixfs-importer will not be able to properly wrap with a directory. We can make this work with:

import IPFS from 'ipfs-core'

const ipfs = await IPFS.create()
const { cid } = await ipfs.add({ content: new Uint8Array([1, 2, 3]), path: '/path/to/file' }, {
  cidVersion: 1,
  wrapWithDirectory: true
})
console.info(cid)

We should either just thrown an error in such cases, or have a path inferred. @achingbrain what do you think to be the expectation here?

Related to storacha/ipfs-car#88

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Low: Not priority right nowexp/beginnerCan be confidently tackled by newcomerskind/maintenanceWork required to avoid breaking changes or harm to project's status quo

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions