Skip to content

Commit

Permalink
Fix compression and make it even simpler (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
majst01 authored Oct 2, 2020
1 parent 4a30382 commit a77bad5
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions cmd/internal/compress/compress.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,19 @@ import (
type (
// Compressor compress/decompress backup data before/after sending/receiving from storage
Compressor struct {
archiver archiver.Archiver
extension string
}
)

// New Returns a new Compressor
func New(method string) (*Compressor, error) {
var c *Compressor
c := &Compressor{}
switch method {
case "tar":
c.archiver = archiver.NewTar()
c.extension = ".tar"
case "targz":
c.archiver = archiver.NewTarGz()
c.extension = ".tar.gz"
case "tarlz4":
c.archiver = archiver.NewTarLz4()
c.extension = ".tar.lz4"
default:
return nil, fmt.Errorf("unsupported compression method: %s", method)
Expand All @@ -38,7 +34,7 @@ func New(method string) (*Compressor, error) {
// Compress the given backupFile and returns the full filename with the extension
func (c *Compressor) Compress(backupFilePath string) (string, error) {
filename := backupFilePath + c.extension
return filename, c.archiver.Archive([]string{constants.BackupDir}, filename)
return filename, archiver.Archive([]string{constants.BackupDir}, filename)
}

// Decompress the given backupFile
Expand Down

0 comments on commit a77bad5

Please sign in to comment.