admin: Can gunzip files
This commit is contained in:
parent
c082ee43d0
commit
a0cd651dae
4 changed files with 83 additions and 3 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package fic
|
||||
|
||||
import (
|
||||
"compress/gzip"
|
||||
"crypto"
|
||||
_ "crypto/sha1"
|
||||
"encoding/hex"
|
||||
|
|
@ -403,3 +404,35 @@ func (f *EFile) CheckFileOnDisk() error {
|
|||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// GunzipFileOnDisk gunzip a compressed file.
|
||||
func (f *EFile) GunzipFileOnDisk() error {
|
||||
if !strings.HasSuffix(f.origin, ".gz") || strings.HasSuffix(f.origin, ".tar.gz") {
|
||||
return nil
|
||||
}
|
||||
|
||||
fdIn, err := os.Open(path.Join(FilesDir, f.Path+".gz"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer fdIn.Close()
|
||||
|
||||
fdOut, err := os.Create(path.Join(FilesDir, strings.TrimSuffix(f.Path, ".gz")))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer fdOut.Close()
|
||||
|
||||
gunzipfd, err := gzip.NewReader(fdIn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer gunzipfd.Close()
|
||||
|
||||
_, err = io.Copy(fdOut, gunzipfd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue