apkdoc @ dd2a1c38a5a9f561d58b58da56d3230fd715fcde

 1package main
 2
 3import (
 4	"archive/tar"
 5	"bufio"
 6	"compress/gzip"
 7	"errors"
 8	"flag"
 9	"fmt"
10	"io"
11	"net/http"
12)
13
14func fechIndex(url string) (io.ReadCloser, error) {
15	resp, err := http.Get(url)
16	if err != nil {
17		return nil, err
18	}
19
20	if resp.StatusCode != 200 {
21		return nil, errors.New("Invlid response")
22	}
23
24	return resp.Body, nil
25}
26
27func main() {
28	url := flag.String("url", "", "Url to the APKINDEX.tar.gz")
29	flag.Parse()
30
31	tarStream, err := fechIndex(*url)
32	if err != nil {
33		panic("Error fecthing the index: " + err.Error())
34	}
35
36	defer tarStream.Close()
37
38	archive, err := gzip.NewReader(tarStream)
39	if err != nil {
40		panic("Error creating gzip reader: " + err.Error())
41	}
42
43	tr := tar.NewReader(archive)
44
45	for {
46		h, err := tr.Next()
47		if err != nil {
48			panic("Error reading next tar entry: " + err.Error())
49		}
50
51		if h.FileInfo().Name() == "APKINDEX" {
52			break
53		}
54	}
55
56	s := bufio.NewScanner(tr)
57
58	entries := make([]*Entry, 0)
59	lines := make([]string, 0)
60
61	for s.Scan() {
62		l := s.Text()
63		if l == "" {
64			entry := Parse(lines)
65			entries = append(entries, entry)
66			lines = make([]string, 0)
67		} else {
68			lines = append(lines, l)
69		}
70	}
71
72	for _, e := range entries {
73		fmt.Printf("%+v\n", e)
74	}
75}