github.com/angenalZZZ/gofunc@v0.0.0-20210507121333-48ff1be3917b/f/zip_test.go (about) 1 package f_test 2 3 import ( 4 "github.com/angenalZZZ/gofunc/f" 5 "os" 6 "testing" 7 ) 8 9 func TestZipCompress(t *testing.T) { 10 // Zip Compress 11 destination, sources := "../test/rsa.zip", []string{ 12 "../test/rsa", 13 } 14 15 if f.FileExists(destination) { 16 t.Logf(" file exists: %s , is zip file: %t\n", destination, f.IsZipFile(destination)) 17 } 18 19 if err := f.ZipCompress(sources, destination, true, false); err != nil { 20 t.Fatal(err) 21 } 22 23 // Zip Decompress 24 reader, err := f.ZipOpenReader(destination) 25 if err != nil { 26 t.Fatal(err) 27 } 28 29 defer func() { 30 _ = reader.Close() 31 _ = os.Remove(destination) 32 }() 33 34 if err := f.ZipDecompress(&reader.Reader, "../test/"); err != nil { 35 t.Fatal(err) 36 } 37 }