Created
November 2, 2017 07:47
-
-
Save jianchen2580/88b568cac5670dad81fd75b576858337 to your computer and use it in GitHub Desktop.
Golang gzip Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func gzipFile(in string) (string, error) { | |
in, err := os.Open(in) | |
defer in.Close() | |
if err != nil { | |
return "", err | |
} | |
out, err := os.Create(fmt.Sprintf("%s.gz", in)) | |
defer out.Close() | |
if err != nil { | |
return "", err | |
} | |
gzipW := gzip.NewWriter(out) | |
defer gzipW.Close() | |
if _, err := io.Copy(gzipW, in); err != nil { | |
return "", err | |
} | |
return out, nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment