Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

s2: Use official snappy framed extension #610

Merged
merged 1 commit into from
Jun 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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