mirror of
https://github.com/pldubouilh/gossa
synced 2025-12-06 08:22:32 +01:00
better zip
This commit is contained in:
parent
688be87923
commit
2f73fd9df8
2 changed files with 16 additions and 7 deletions
5
gossa.go
5
gossa.go
|
|
@ -193,7 +193,10 @@ func walkZip(wz *zip.Writer, fp, baseInZip string) {
|
||||||
if !file.IsDir() {
|
if !file.IsDir() {
|
||||||
data, err := ioutil.ReadFile(fp + file.Name())
|
data, err := ioutil.ReadFile(fp + file.Name())
|
||||||
check(err)
|
check(err)
|
||||||
f, err := wz.Create(baseInZip + file.Name())
|
f, err := wz.CreateHeader(&zip.FileHeader{
|
||||||
|
Name: baseInZip + file.Name(),
|
||||||
|
Method: zip.Store, // dont compress
|
||||||
|
})
|
||||||
check(err)
|
check(err)
|
||||||
_, err = f.Write(data)
|
_, err = f.Write(data)
|
||||||
check(err)
|
check(err)
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"archive/zip"
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto/sha256"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
@ -30,6 +30,13 @@ func getRaw(t *testing.T, url string) []byte {
|
||||||
return body
|
return body
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getZip(t *testing.T, dest string) []*zip.File {
|
||||||
|
b := getRaw(t, dest)
|
||||||
|
archive, err := zip.NewReader(bytes.NewReader(b), int64(len(b)))
|
||||||
|
dieMaybe(t, err)
|
||||||
|
return archive.File
|
||||||
|
}
|
||||||
|
|
||||||
func get(t *testing.T, url string) string {
|
func get(t *testing.T, url string) string {
|
||||||
body := getRaw(t, url)
|
body := getRaw(t, url)
|
||||||
return trimSpaces(string(body))
|
return trimSpaces(string(body))
|
||||||
|
|
@ -119,11 +126,10 @@ func doTestRegular(t *testing.T, url string, testExtra bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ~~~~~~~~~~~~~~~~~
|
// ~~~~~~~~~~~~~~~~~
|
||||||
fmt.Println("\r\n~~~~~~~~~~ test zip")
|
fmt.Println("\r\n~~~~~~~~~~ test zipping of folder 中文")
|
||||||
bodyRaw := getRaw(t, url+"zip?zipPath=%2F%E4%B8%AD%E6%96%87%2F&zipName=%E4%B8%AD%E6%96%87")
|
files := getZip(t, url+"zip?zipPath=%2F%E4%B8%AD%E6%96%87%2F&zipName=%E4%B8%AD%E6%96%87")
|
||||||
hashStr := fmt.Sprintf("%x", sha256.Sum256(bodyRaw))
|
if len(files) != 1 || files[0].Name != "檔案.html" {
|
||||||
if hashStr != "b02436a76b149e6c4458bbbe622ab7c5e789bb0d26b87f604cf0f989cfaf669f" {
|
t.Fatal("invalid zip generated")
|
||||||
t.Fatal("invalid zip checksum", hashStr)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ~~~~~~~~~~~~~~~~~
|
// ~~~~~~~~~~~~~~~~~
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue