mirror of
https://github.com/grafana/loki.git
synced 2026-03-13 09:33:58 +08:00
This PR renames "encoding" to "codec" in the compression package to remove the cognitive dissonance. It also removes the `Enc` prefix for codec identifiers, so that they adhere Go's best practice of naming conventions, e.g. `compression.EncGZIP` becomes `compression.GZIP` when used in a different package. Signed-off-by: Christian Haudum <christian.haudum@gmail.com>
51 lines
822 B
Go
51 lines
822 B
Go
package compression
|
|
|
|
import "fmt"
|
|
|
|
const (
|
|
ExtNone = ""
|
|
ExtGZIP = ".gz"
|
|
ExtSnappy = ".sz"
|
|
ExtLZ4 = ".lz4"
|
|
ExtFlate = ".zz"
|
|
ExtZstd = ".zst"
|
|
)
|
|
|
|
func ToFileExtension(e Codec) string {
|
|
switch e {
|
|
case None:
|
|
return ExtNone
|
|
case GZIP:
|
|
return ExtGZIP
|
|
case LZ4_64k, LZ4_256k, LZ4_1M, LZ4_4M:
|
|
return ExtLZ4
|
|
case Snappy:
|
|
return ExtSnappy
|
|
case Flate:
|
|
return ExtFlate
|
|
case Zstd:
|
|
return ExtZstd
|
|
default:
|
|
panic(fmt.Sprintf("invalid codec: %d, supported: %s", e, SupportedCodecs()))
|
|
}
|
|
}
|
|
|
|
func FromFileExtension(ext string) Codec {
|
|
switch ext {
|
|
case ExtNone:
|
|
return None
|
|
case ExtGZIP:
|
|
return GZIP
|
|
case ExtLZ4:
|
|
return LZ4_4M
|
|
case ExtSnappy:
|
|
return Snappy
|
|
case ExtFlate:
|
|
return Flate
|
|
case ExtZstd:
|
|
return Zstd
|
|
default:
|
|
panic(fmt.Sprintf("invalid file extension: %s", ext))
|
|
}
|
|
}
|