Skip to content

A Golang library to read and serve ZIM archives.

License

Notifications You must be signed in to change notification settings

Bornholm/go-zim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-zim

Go Reference

A Golang library to read and serve ZIM archives.

Inspired by github.com/tim-st/go-zim.

Usage

Reading a ZIM file

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())
}

Serving a ZIM file with a HTTP server

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.

License

MIT

About

A Golang library to read and serve ZIM archives.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages