diff --git a/s2/cmd/s2c/main.go b/s2/cmd/s2c/main.go index 7c43f11e18..9d4af2a1ee 100644 --- a/s2/cmd/s2c/main.go +++ b/s2/cmd/s2c/main.go @@ -51,6 +51,11 @@ var ( date = "(unknown)" ) +const ( + s2Ext = ".s2" + snappyExt = ".sz" // https://github.com/google/snappy/blob/main/framing_format.txt#L34 +) + func main() { if false { flag.StringVar(&cpuprofile, "cpuprofile", "", "write cpu profile to file") @@ -71,7 +76,7 @@ func main() { _, _ = fmt.Fprintln(os.Stderr, `Usage: s2c [options] file1 file2 Compresses all files supplied as input separately. -Output files are written as 'filename.ext.s2' or 'filename.ext.snappy'. +Output files are written as 'filename.ext`+s2Ext+`' or 'filename.ext`+snappyExt+`'. By default output files will be overwritten. Use - as the only file name to read from stdin and write to stdout. @@ -325,9 +330,9 @@ Options:`) } os.Exit(0) } - ext := ".s2" + ext := s2Ext if *snappy { - ext = ".snappy" + ext = snappyExt } if *block { ext += ".block" diff --git a/s2/cmd/s2d/main.go b/s2/cmd/s2d/main.go index cebfab67f3..5fc0abe692 100644 --- a/s2/cmd/s2d/main.go +++ b/s2/cmd/s2d/main.go @@ -41,6 +41,11 @@ var ( date = "(unknown)" ) +const ( + s2Ext = ".s2" + snappyExt = ".sz" // https://github.com/google/snappy/blob/main/framing_format.txt#L34 +) + func main() { flag.Parse() r := s2.NewReader(nil) @@ -53,7 +58,7 @@ func main() { "Copyright (c) 2019+ Klaus Post. All rights reserved.\n\n") _, _ = fmt.Fprintln(os.Stderr, `Usage: s2d [options] file1 file2 -Decompresses all files supplied as input. Input files must end with '.s2' or '.snappy'. +Decompresses all files supplied as input. Input files must end with '`+s2Ext+`' or '`+snappyExt+`'. Output file names have the extension removed. By default output files will be overwritten. Use - as the only file name to read from stdin and write to stdout. @@ -130,7 +135,8 @@ Options:`) block = true } switch { - case strings.HasSuffix(dstFilename, ".s2"): + case strings.HasSuffix(dstFilename, s2Ext): + case strings.HasSuffix(dstFilename, snappyExt): case strings.HasSuffix(dstFilename, ".snappy"): default: if !isHTTP(filename) { @@ -199,8 +205,10 @@ Options:`) switch { case *out != "": dstFilename = *out - case strings.HasSuffix(dstFilename, ".s2"): - dstFilename = strings.TrimSuffix(dstFilename, ".s2") + case strings.HasSuffix(dstFilename, s2Ext): + dstFilename = strings.TrimSuffix(dstFilename, s2Ext) + case strings.HasSuffix(dstFilename, snappyExt): + dstFilename = strings.TrimSuffix(dstFilename, snappyExt) case strings.HasSuffix(dstFilename, ".snappy"): dstFilename = strings.TrimSuffix(dstFilename, ".snappy") default: