-
Notifications
You must be signed in to change notification settings - Fork 0
/
18.go
128 lines (103 loc) · 2.93 KB
/
18.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package main
import (
"fmt"
"os"
"compress/gzip"
_"strconv"
"bytes"
"encoding/hex"
"strings"
"reflect"
"net/http"
"io"
"github.com/pmezard/go-difflib/difflib"
)
var buffer *bytes.Buffer
func main() {
// observation/ 3 slots of 32/sp in the middle
// len/108 ...
// 52 / 48 uint8
// 53 / 32 uint8
// 54 / 32 uint8
// 55 / 32 uint8
// 56 / 56 uint8
var L, R []string
lines := strings.Split(buffer.String(), "\n")
for _, line := range lines {
if len(line) < 56 {
fmt.Println("empty?/", len(line))
//L = append(L, line)
//continue
} else {
L = append(L, line[:53])
R = append(R, line[56:])
}
}
// create images
p1, _ := os.Create("p1.png")
defer p1.Close()
p2, _ := os.Create("p2.png")
defer p2.Close()
p3, _ := os.Create("p3.png")
defer p3.Close()
diff, _ := difflib.GetUnifiedDiffString( difflib.UnifiedDiff {
A: difflib.SplitLines(strings.Join(L, "\n")),
B: difflib.SplitLines(strings.Join(R, "\n")),
Context: len(L), // <--- FIXME/ bugfix: 3 is too small thats all
})
// print out the whole DIFF sequence
fmt.Println(diff[4096:8192], "\nend/")
for i, line := range strings.Split(diff, "\n") {
//if i == 100 {break}
if len(line) == 0 {
fmt.Println("line/", i, "(null)")
continue
}
bytes := []byte{}
if !strings.HasPrefix(line, "@") {
data := line[1:]
bytes, _ = hexpair(data)
}
if strings.HasPrefix(line, "+") {
p1.Write(bytes)
} else if strings.HasPrefix(line, "-") {
p2.Write(bytes)
} else if strings.HasPrefix(line, " ") {
//fmt.Println(i, bytes)
p3.Write(bytes)
} else if strings.HasPrefix(line, "@"){
fmt.Println(i, "@ lines/", line)
} else {
fmt.Println(i, "default/", line)
}
}
}
func hexpair(hexstring string) ([]byte, error) {
res := strings.ReplaceAll(hexstring, " ", "")
if len(res) % 2 != 0 {
res = "0" + res
}
return hex.DecodeString(res)
}
func init() {
// todo/ download the gz
Filename := "deltas.gz"
URL := "http://www.pythonchallenge.com/pc/return/" + Filename
conn := & http.Client{}
req, err := http.NewRequest("GET", URL, nil)
fmt.Println("1/", err)
req.SetBasicAuth("huge", "file")
resp, err := conn.Do(req)
defer resp.Body.Close()
fmt.Println("2/", err)
f, err := os.Create( Filename )
defer f.Close()
_, _ = io.Copy(f, resp.Body)
fmt.Println("3/", err)
gzfile, _ := os.Open( Filename )
gzReader, _ := gzip.NewReader( gzfile )
defer gzReader.Close()
buffer = new(bytes.Buffer)
_, _ = buffer.ReadFrom(gzReader)
fmt.Println(reflect.TypeOf( buffer ))
}