Skip to content

Commit 479aeb7

Browse files
author
hero
committed
合并文件操作
1 parent 3797438 commit 479aeb7

File tree

1 file changed

+62
-1
lines changed

1 file changed

+62
-1
lines changed

minio/minio_test.go

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ var minioClient *minio.Client
1212

1313
func init() {
1414
var err error
15+
//s3.amazonaws.com
16+
//127.0.0.1:9000
1517
minioClient, err = minio.New("127.0.0.1:9000", "AKIAINCHU2DIYAQ66TPA", "ZaYtz0d61fJXQ7djyXBX4yZ5ob8Kj/WNXtw6PJob", false)
1618
if err != nil {
1719
panic(err)
@@ -34,6 +36,49 @@ func TestGetObject(t *testing.T) {
3436
}
3537
fmt.Println(string(data))
3638
}
39+
func TestPutObject(t *testing.T) {
40+
/*_,err:=minioClient.PutObject("test","3",strings.NewReader("3"),int64(len("1")),minio.PutObjectOptions{})
41+
if err != nil {
42+
panic(err)
43+
}*/
44+
info,err:=minioClient.StatObject("test","1",minio.StatObjectOptions{})
45+
if err != nil {
46+
panic(err)
47+
}
48+
fmt.Println(info)
49+
fmt.Println(info.ETag)
50+
}
51+
52+
53+
func TestComposeObject(t *testing.T) {
54+
bucketName:="test"
55+
var srcs =make([]minio.SourceInfo,0)
56+
for i:=0;i<3;i++{
57+
name:=fmt.Sprintf("sheet_%d",i)
58+
bbuf := bytes.Repeat([]byte(fmt.Sprint(i+1)), 1024*1025*5)//至少要5M
59+
60+
index,err:=minioClient.PutObject(bucketName,name,bytes.NewReader(bbuf),int64(len(bbuf)),minio.PutObjectOptions{})
61+
if err!=nil{
62+
panic(err)
63+
}
64+
fmt.Println(index)
65+
srcs=append(srcs,minio.NewSourceInfo(bucketName,fmt.Sprintf("sheet_%d",i),nil))
66+
}
67+
fmt.Println(srcs)
68+
dst, err := minio.NewDestinationInfo("test", "222.log", nil, nil)
69+
if err != nil {
70+
fmt.Println(err)
71+
return
72+
}
73+
fmt.Println(dst)
74+
err = minioClient.ComposeObject(dst, srcs)
75+
if err != nil {
76+
fmt.Println(err)
77+
return
78+
}
79+
fmt.Println("Composed object successfully.")
80+
}
81+
3782

3883
func TestNewMultipartUpload(t *testing.T) {
3984
daya := minio.Core{Client: minioClient}
@@ -46,7 +91,8 @@ func TestNewMultipartUpload(t *testing.T) {
4691
}
4792

4893
func TestNewPutObjectPart(t *testing.T) {
49-
abuf := bytes.Repeat([]byte("aaaaa"), 1024*1024)//至少要5MB 才能使用分片上传
94+
abuf := bytes.Repeat([]byte("aaaaa"), 1024*1024)//至少要5MB 才能使用分片上传(不包含最后一片)
95+
fmt.Println(len(abuf))
5096
bbuf := bytes.Repeat([]byte("b"), 1024*1024)
5197
daya := minio.Core{Client: minioClient}
5298
bucket:="test"
@@ -77,3 +123,18 @@ func TestNewPutObjectPart(t *testing.T) {
77123
panic(err)
78124
}
79125
}
126+
127+
func TestConsolidatedFile(t *testing.T) {
128+
bucketName:="test"
129+
var srcs =make([]minio.SourceInfo,0)
130+
for i:=0;i<3;i++{
131+
name:=fmt.Sprintf("sheet_%d",i)
132+
bbuf := bytes.Repeat([]byte(fmt.Sprint(i+1)), 1)//至少要5M
133+
index,err:=minioClient.PutObject(bucketName,name,bytes.NewReader(bbuf),int64(len(bbuf)),minio.PutObjectOptions{})
134+
if err!=nil{
135+
panic(err)
136+
}
137+
fmt.Println(index)
138+
srcs=append(srcs,minio.NewSourceInfo(bucketName,fmt.Sprintf("sheet_%d",i),nil))
139+
}
140+
}

0 commit comments

Comments
 (0)