• Import a file directly from a URL. The path of the file will be the path section of the URL.

    Parameters

    • url: string | URL
    • Optional options: RequestInit

    Returns FileCandidate<AsyncGenerator<Uint8Array, void, unknown>>

    Example

    import { unixfs, urlSource } from '@helia/unixfs'
    import { createHelia } from 'helia'

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

    const cid = await fs.addFile(urlSource('http://example.com/path/to/file.html))
    const stat = await fs.stat(cid)

    console.info(stat)
    // { cid: CID(...), type: 'directory', ... }

    for await (const entry of fs.ls(cid)) {
    console.info(entry)
    // { type: 'file', name: 'file.html', cid: CID(...), ... }
    }