Add all files and directories from the passed stream. This method wraps the
importer
export from the ipfs-unixfs-importer
module - please see the docs
for input/output types.
Optional
options: Partial<AddOptions>const source = [{
path: './foo.txt',
content: Uint8Array.from([0, 1, 2, 3])
}, {
path: './bar.txt',
content: Uint8Array.from([4, 5, 6, 7])
}]
for await (const entry of fs.import(source)) {
console.info(entry)
}
Add a stream of Uint8Array
to your Helia node as a file.
Optional
options: Partial<AddOptions>import fs from 'fs'
const stream = fs.createReadStream('./foo.txt')
const cid = await fs.addByteStream(stream)
console.info(cid)
Add a single Uint8Array
to your Helia node as a file.
Optional
options: Partial<AddOptions>const cid = await fs.addBytes(Uint8Array.from([0, 1, 2, 3]))
console.info(cid)
Add a directory to your Helia node.
Optional
dir: Partial<DirectoryCandidate>Optional
options: Partial<AddOptions>const cid = await fs.addDirectory()
console.info(cid)
Add a file to your Helia node with optional metadata.
Optional
options: Partial<AddOptions>const cid = await fs.addFile({
path: './foo.txt',
content: Uint8Array.from([0, 1, 2, 3]),
mode: 0x755,
mtime: {
secs: 10n,
nsecs: 0
}
})
console.info(cid)
Retrieve the contents of a file from your Helia node.
Optional
options: Partial<CatOptions>for await (const buf of fs.cat(cid)) {
console.info(buf)
}
Change the permissions on a file or directory in a DAG
Optional
options: Partial<ChmodOptions>const beforeCid = await fs.addBytes(Uint8Array.from([0, 1, 2, 3]))
const beforeStats = await fs.stat(beforeCid)
const afterCid = await fs.chmod(cid, 0x755)
const afterStats = await fs.stat(afterCid)
console.info(beforeCid, beforeStats)
console.info(afterCid, afterStats)
Add a file or directory to a target directory.
const fileCid = await fs.addBytes(Uint8Array.from([0, 1, 2, 3]))
const directoryCid = await fs.addDirectory()
const updatedCid = await fs.cp(fileCid, directoryCid, 'foo.txt')
console.info(updatedCid)
List directory contents.
for await (const entry of fs.ls(directoryCid)) {
console.info(entry)
}
Make a new directory under an existing directory.
Optional
options: Partial<MkdirOptions>const directoryCid = await fs.addDirectory()
const updatedCid = await fs.mkdir(directoryCid, 'new-dir')
console.info(updatedCid)
Remove a file or directory from an existing directory.
const directoryCid = await fs.addDirectory()
const updatedCid = await fs.mkdir(directoryCid, 'new-dir')
const finalCid = await fs.rm(updatedCid, 'new-dir')
console.info(finalCid)
Return statistics about a UnixFS DAG.
Optional
options: Partial<StatOptions>const fileCid = await fs.addBytes(Uint8Array.from([0, 1, 2, 3]))
const stats = await fs.stat(fileCid)
console.info(stats)
Update the mtime of a UnixFS DAG
Optional
options: Partial<TouchOptions>const beforeCid = await fs.addBytes(Uint8Array.from([0, 1, 2, 3]))
const beforeStats = await fs.stat(beforeCid)
const afterCid = await fs.touch(beforeCid)
const afterStats = await fs.stat(afterCid)
console.info(beforeCid, beforeStats)
console.info(afterCid, afterStats)
The UnixFS interface provides familiar filesystem operations to make working with UnixFS DAGs simple and intuitive.