FileSystem API¶
The FileSystem class provides low-level access to the content-addressable DAG.
Constructor¶
Basic Operations¶
read(path) -> Optional[bytes]¶
Read file contents.
write(path, content) -> bool¶
Write content to file.
exists(path) -> bool¶
Check if path exists.
stat(path) -> Optional[Dict]¶
Get file information.
info = fs.stat("/file.txt")
# Returns:
# {
# 'type': 'file',
# 'size': 1234,
# 'mode': 0o644,
# 'uid': 1000,
# 'gid': 1000,
# 'mtime': 1234567890.0
# }
ls(path) -> Optional[List[str]]¶
List directory contents.
Directory Operations¶
mkdir(path) -> bool¶
Create directory.
rmdir(path) -> bool¶
Remove empty directory.
File Management¶
unlink(path) -> bool¶
Remove file.
rename(old, new) -> bool¶
Rename/move file.
Links¶
symlink(target, path) -> bool¶
Create symbolic link.
readlink(path) -> Optional[str]¶
Read symbolic link target.
Permissions¶
chmod(path, mode) -> bool¶
Change file mode.
chown(path, uid, gid) -> bool¶
Change ownership.
can_read(path, uid, gid) -> bool¶
can_write(path, uid, gid) -> bool¶
can_execute(path, uid, gid) -> bool¶
Check permissions.
Serialization¶
to_json() -> str¶
Serialize filesystem to JSON.
from_json(json_str) -> FileSystem¶
Load filesystem from JSON.
Node Access¶
get_node(hash) -> Optional[Node]¶
Get node by hash.
Node Types¶
from dagshell.dagshell import FileNode, DirNode, SymlinkNode, DeviceNode
# Check node type
node = fs.get_node(hash)
if node.is_file():
print(node.content)
elif node.is_dir():
print(node.entries)
elif node.is_symlink():
print(node.target)