mirror of
https://github.com/bettercap/bettercap
synced 2025-08-20 13:33:21 -07:00
new: added log rotation (closes #374)
This commit is contained in:
parent
b6f320d719
commit
fc7d8d22b4
5 changed files with 161 additions and 7 deletions
55
vendor/github.com/evilsocket/islazy/zip/files.go
generated
vendored
Normal file
55
vendor/github.com/evilsocket/islazy/zip/files.go
generated
vendored
Normal file
|
@ -0,0 +1,55 @@
|
|||
package zip
|
||||
|
||||
import (
|
||||
"archive/zip"
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Files compresses one or many files into a single zip archive file.
|
||||
// Credits: https://golangcode.com/create-zip-files-in-go/
|
||||
func Files(filename string, files []string) error {
|
||||
arc, err := os.Create(filename)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer arc.Close()
|
||||
|
||||
writer := zip.NewWriter(arc)
|
||||
defer writer.Close()
|
||||
|
||||
for _, file := range files {
|
||||
in, err := os.Open(file)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer in.Close()
|
||||
|
||||
info, err := in.Stat()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
header, err := zip.FileInfoHeader(info)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Using FileInfoHeader() above only uses the basename of the file. If we want
|
||||
// to preserve the folder structure we can overwrite this with the full path.
|
||||
header.Name = file
|
||||
// Change to deflate to gain better compression
|
||||
// see http://golang.org/pkg/archive/zip/#pkg-constants
|
||||
header.Method = zip.Deflate
|
||||
|
||||
w, err := writer.CreateHeader(header)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err = io.Copy(w, in); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue