Skip to content

Commit

Permalink
s2: Use official snappy framed extension (#610)
Browse files Browse the repository at this point in the history
(but keep `.snappy` for backcompat)
  • Loading branch information
klauspost authored Jun 1, 2022
1 parent 30a82ca commit d0cd1a9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
11 changes: 8 additions & 3 deletions s2/cmd/s2c/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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.
Expand Down Expand Up @@ -325,9 +330,9 @@ Options:`)
}
os.Exit(0)
}
ext := ".s2"
ext := s2Ext
if *snappy {
ext = ".snappy"
ext = snappyExt
}
if *block {
ext += ".block"
Expand Down
16 changes: 12 additions & 4 deletions s2/cmd/s2d/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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.
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit d0cd1a9

Please sign in to comment.