-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathzip_reader_test.go
113 lines (104 loc) · 2.67 KB
/
zip_reader_test.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
package unzip
import (
"fmt"
"testing"
"github.com/go-pay/xlog"
)
func TestReadFileFromURLByName(t *testing.T) {
xlog.Level = xlog.DebugLevel
zipUrl := "https://tangboedu-1010.oss-cn-hangzhou.aliyuncs.com/remoteFile.zip"
zr, err := NewZipReader(ctx, zipUrl)
if err != nil {
xlog.Errorf("err:%v", err)
}
fileMap, err := zr.ReadFileByName(ctx, []string{"other.txt"})
if err != nil {
fmt.Println(err)
return
}
for k, v := range fileMap {
fmt.Println("path:", k)
fmt.Println(string(v))
}
}
func TestReadFileFromURLByPath(t *testing.T) {
xlog.Level = xlog.DebugLevel
zipUrl := "https://tangboedu-1010.oss-cn-hangzhou.aliyuncs.com/remoteFile.zip"
zr, err := NewZipReader(ctx, zipUrl)
if err != nil {
xlog.Errorf("err:%v", err)
}
fileStream, err := zr.ReadFileByPath(ctx, "/remoteFile/level1/level2/level3/version3.txt")
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(fileStream))
}
func TestPrintDirectoryFromURL(t *testing.T) {
xlog.Level = xlog.DebugLevel
zipUrl := "https://tangboedu-1010.oss-cn-hangzhou.aliyuncs.com/remoteFile.zip"
zr, err := NewZipReader(ctx, zipUrl)
if err != nil {
xlog.Errorf("err:%v", err)
}
err = zr.PrintDirectory()
if err != nil {
xlog.Errorf("err:%v", err)
}
}
func TestDownZipFileFromURL(t *testing.T) {
xlog.Level = xlog.DebugLevel
zipUrl := "https://tangboedu-1010.oss-cn-hangzhou.aliyuncs.com/remoteFile.zip"
zr, err := NewZipReader(ctx, zipUrl)
if err != nil {
xlog.Errorf("err:%v", err)
}
err = zr.DownloadRemoteFile(ctx, []string{"version1.txt"}, "/Users/jerry/Downloads")
if err != nil {
xlog.Errorf("err:%v", err)
}
}
func TestPrintDirectoryFromLocal(t *testing.T) {
xlog.Level = xlog.DebugLevel
zipUrl := "/Users/jerry/Downloads/remoteFile.zip"
zr, err := NewZipReader(ctx, zipUrl)
if err != nil {
xlog.Errorf("err:%v", err)
}
err = zr.PrintDirectory()
if err != nil {
xlog.Errorf("err:%v", err)
}
}
func TestReadFileFromLocalByName(t *testing.T) {
xlog.Level = xlog.DebugLevel
zipUrl := "/Users/jerry/Downloads/remoteFile.zip"
zr, err := NewZipReader(ctx, zipUrl)
if err != nil {
xlog.Errorf("err:%v", err)
}
fileMap, err := zr.ReadFileByName(ctx, []string{"other.txt"})
if err != nil {
fmt.Println(err)
return
}
for k, v := range fileMap {
fmt.Println("path:", k)
fmt.Println(string(v))
}
}
func TestReadFileFromLocalByPath(t *testing.T) {
xlog.Level = xlog.DebugLevel
zipUrl := "/Users/jerry/Downloads/remoteFile.zip"
zr, err := NewZipReader(ctx, zipUrl)
if err != nil {
xlog.Errorf("err:%v", err)
}
fileStream, err := zr.ReadFileByPath(ctx, "/remoteFile/level1/level2/level3/version3.txt")
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(fileStream))
}