A Golang library to read and serve ZIM archives.
Inspired by github.com/tim-st/go-zim
.
package main
import (
"flag"
"net/http"
"github.com/Bornholm/go-zim"
)
func main() {
reader, err := zim.Open("my-archive.zim")
if err != nil {
panic(err)
}
defer func() {
if err := reader.Close(); err != nil {
panic(err)
}
}()
fmt.Println("Entries count:", reader.EntryCount())
mainPage, err := reader.MainPage()
if err != nil {
panic(err)
}
fmt.Println("Main Page Title:", mainPage.Title())
fmt.Println("Main Page Full URL:", mainPage.FullURL())
}
package main
import (
"flag"
"net/http"
"github.com/Bornholm/go-zim"
zimFS "github.com/Bornholm/go-zim/fs"
)
func main() {
reader, err := zim.Open(zimPath)
if err != nil {
panic(err)
}
defer func() {
if err := reader.Close(); err != nil {
panic(err)
}
}()
fs := zimFS.New(reader)
fileServer := http.FileServer(http.FS(fs))
if err := http.ListenAndServe(":8080", fileServer); err != nil {
panic(err)
}
}
See examples/zim-server
for an runnable example.