84 lines
1.7 KiB
Go
84 lines
1.7 KiB
Go
|
package zim
|
||
|
|
||
|
import (
|
||
|
"log"
|
||
|
"path/filepath"
|
||
|
"testing"
|
||
|
|
||
|
"github.com/davecgh/go-spew/spew"
|
||
|
"github.com/pkg/errors"
|
||
|
)
|
||
|
|
||
|
func TestReader(t *testing.T) {
|
||
|
files, err := filepath.Glob("testdata/*.zim")
|
||
|
if err != nil {
|
||
|
t.Fatalf("%+v", errors.WithStack(err))
|
||
|
}
|
||
|
|
||
|
for _, zf := range files {
|
||
|
testName := filepath.Base(zf)
|
||
|
t.Run(testName, func(t *testing.T) {
|
||
|
reader, err := Open(zf)
|
||
|
if err != nil {
|
||
|
t.Fatalf("%+v", errors.WithStack(err))
|
||
|
}
|
||
|
|
||
|
defer func() {
|
||
|
if err := reader.Close(); err != nil {
|
||
|
t.Fatalf("%+v", errors.WithStack(err))
|
||
|
}
|
||
|
}()
|
||
|
|
||
|
iterator := reader.Entries()
|
||
|
for iterator.Next() {
|
||
|
entry := iterator.Entry()
|
||
|
|
||
|
content, err := entry.Redirect()
|
||
|
if err != nil {
|
||
|
t.Errorf("%+v", errors.WithStack(err))
|
||
|
break
|
||
|
}
|
||
|
|
||
|
log.Printf("%s/%s: %s", content.Namespace(), content.URL(), content.Title())
|
||
|
|
||
|
contentReader, err := content.Reader()
|
||
|
if err != nil {
|
||
|
t.Errorf("%+v", errors.WithStack(err))
|
||
|
break
|
||
|
}
|
||
|
|
||
|
spew.Dump(contentReader)
|
||
|
}
|
||
|
if err := iterator.Err(); err != nil {
|
||
|
if err != nil {
|
||
|
t.Errorf("%+v", errors.WithStack(err))
|
||
|
}
|
||
|
}
|
||
|
})
|
||
|
|
||
|
// entry, err := reader.EntryWithURL(V6NamespaceContent, "A/a.tile.openstreetmap.org/16/33682/22970.png")
|
||
|
// if err != nil {
|
||
|
// t.Fatalf("%+v", errors.WithStack(err))
|
||
|
// }
|
||
|
|
||
|
// content, err := entry.Redirect()
|
||
|
// if err != nil {
|
||
|
// t.Fatalf("%+v", errors.WithStack(err))
|
||
|
// }
|
||
|
|
||
|
// contentReader, err := content.Reader()
|
||
|
// if err != nil {
|
||
|
// t.Fatalf("%+v", errors.WithStack(err))
|
||
|
// break
|
||
|
// }
|
||
|
|
||
|
// data, err := io.ReadAll(contentReader)
|
||
|
// if err != nil {
|
||
|
// t.Fatalf("%+v", errors.WithStack(err))
|
||
|
// break
|
||
|
// }
|
||
|
|
||
|
// spew.Dump(data)
|
||
|
}
|
||
|
}
|