-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
67 lines (54 loc) · 1.67 KB
/
main.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
package main
import (
"archive/zip"
"context"
"fmt"
"io"
"net/http"
"net/http/httptrace"
bufra "github.com/avvmoto/buf-readerat"
"github.com/snabb/httpreaderat"
)
func main() {
// client trace to log whether the request's underlying tcp connection was re-used
clientTrace := &httptrace.ClientTrace{
GotConn: func(info httptrace.GotConnInfo) {
fmt.Printf("%s conn reused? %v\n", info.Conn.RemoteAddr(), info.Reused)
},
}
traceCtx := httptrace.WithClientTrace(context.Background(), clientTrace)
// ---
url := "https://github.com/ogri-la/ziptest/releases/download/0.0.1/the-undermine-journal--5-6-20220531.zip"
client := http.Client{}
req, err := http.NewRequestWithContext(traceCtx, http.MethodGet, url, nil)
if err != nil {
panic("error creating request: " + err.Error())
}
// ---
http_readerat, err := httpreaderat.New(&client, req, nil)
if err != nil {
panic("error creating HTTPReaderAt: " + err.Error())
}
buffered_http_readerat := bufra.NewBufReaderAt(http_readerat, 1024*1024)
zip_reader, err := zip.NewReader(buffered_http_readerat, http_readerat.Size())
if err != nil {
panic("error creating zip.Reader: " + err.Error())
}
fmt.Println()
for _, zipfile_entry := range zip_reader.File {
fmt.Println(zipfile_entry.Name)
if zipfile_entry.Name == "TheUndermineJournal/TheUndermineJournal.toc" {
fmt.Println("---")
fh, err := zipfile_entry.Open()
if err != nil {
panic("error opening zipfile entry: " + err.Error())
}
zipfile_entry_bytes, err := io.ReadAll(fh)
if err != nil {
panic("error reading bytes from zipfile entry: " + err.Error())
}
fmt.Println(string(zipfile_entry_bytes))
fmt.Println("---")
}
}
}