Erofs banner
Xe Xe

Erofs

Development community

Description

EROFS fs.FS implementation for Go programs

Installation

This entry records only its repository, not the path inside it, so there is no exact command to give. Open the source below and copy the folder into ~/.claude/skills/, or the file into ~/.claude/agents/.

README

erofs

Pure-Go [EROFS](https://erofs.docs.kernel.org/en/latest/) (Enhanced Read-Only File System) reader and writer. Read EROFS images through Go's `fs.FS` interface, or create new ones with `Builder`. Output is bytewise compatible with the Linux kernel EROFS driver and `mkfs.erofs`.

Reads LZ4, LZMA, DEFLATE, and Zstandard compressed images. Writes LZ4 compressed images with automatic incompressibility detection.

Install

go get github.com/Xe/erofs@latest

Reading an EROFS image

`erofs.Open` accepts any `io.ReaderAt` and returns an `*erofs.FS` implementing `fs.FS`, `fs.StatFS`, and `fs.ReadLinkFS`:

package main

import (
    "fmt"
    "io/fs"
    "log"
    "os"

    "github.com/Xe/erofs"
)

func main() {
    f, err := os.Open("rootfs.erofs")
    if err != nil {
        log.Fatal(err)
    }
    defer f.Close()

    fsys, err := erofs.Open(f)
    if err != nil {
        log.Fatal(err)
    }

    // Read a file.
    data, err := fs.ReadFile(fsys, "etc/hostname")
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println(string(data))

    // List a directory.
    entries, err := fs.ReadDir(fsys, "usr/bin")
    if err != nil {
        log.Fatal(err)
    }
    for _, e := range entries {
        fmt.Println(e.Name())
    }

    // Stat a file.
    info, err := fsys.Stat("etc/passwd")
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("%s: %d bytes\n", info.Name(), info.Size())

    // Read a symlink.
    target, err := fsys.ReadLink("usr/bin/vi")
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println("vi ->", target)
}

Creating an EROFS image

`erofs.NewBuilder` writes to any `io.WriterAt`. Add files individually or walk an existing `fs.FS`:

package main

import (
    "log"
    "os"
    "time"

    "github.com/Xe/erofs"
)

func main() {
    out, err := os.Create("output.erofs")
    if err != nil {
        log.Fatal(err)
    }
    defer out.Close()

    b := erofs.NewBuilder(out,
        erofs.WithBlo