aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go75
1 files changed, 75 insertions, 0 deletions
diff --git a/main.go b/main.go
new file mode 100644
index 0000000..9e64dbb
--- /dev/null
+++ b/main.go
@@ -0,0 +1,75 @@
+package main
+
+import (
+ "archive/tar"
+ "bufio"
+ "compress/gzip"
+ "errors"
+ "flag"
+ "fmt"
+ "io"
+ "net/http"
+)
+
+func fechIndex(url string) (io.ReadCloser, error) {
+ resp, err := http.Get(url)
+ if err != nil {
+ return nil, err
+ }
+
+ if resp.StatusCode != 200 {
+ return nil, errors.New("Invlid response")
+ }
+
+ return resp.Body, nil
+}
+
+func main() {
+ url := flag.String("url", "", "Url to the APKINDEX.tar.gz")
+ flag.Parse()
+
+ tarStream, err := fechIndex(*url)
+ if err != nil {
+ panic("Error fecthing the index: " + err.Error())
+ }
+
+ defer tarStream.Close()
+
+ archive, err := gzip.NewReader(tarStream)
+ if err != nil {
+ panic("Error creating gzip reader: " + err.Error())
+ }
+
+ tr := tar.NewReader(archive)
+
+ for {
+ h, err := tr.Next()
+ if err != nil {
+ panic("Error reading next tar entry: " + err.Error())
+ }
+
+ if h.FileInfo().Name() == "APKINDEX" {
+ break
+ }
+ }
+
+ s := bufio.NewScanner(tr)
+
+ entries := make([]*Entry, 0)
+ lines := make([]string, 0)
+
+ for s.Scan() {
+ l := s.Text()
+ if l == "" {
+ entry := Parse(lines)
+ entries = append(entries, entry)
+ lines = make([]string, 0)
+ } else {
+ lines = append(lines, l)
+ }
+ }
+
+ for _, e := range entries {
+ fmt.Printf("%+v\n", e)
+ }
+}