Add --compression-fast to use fastest compression method instead of best

This commit is contained in:
Seednode 2024-01-05 21:42:22 -06:00
parent 965d3deb8d
commit 59cbd25e7c
3 changed files with 73 additions and 53 deletions

View File

@ -151,7 +151,8 @@ Flags:
--case-sensitive use case-sensitive matching for filters
--code enable support for source code files
--code-theme string theme for source code syntax highlighting (default "solarized-dark256")
--compression string compression format to use for index (flate, gzip, lzw, none, zlib, zstd) (default "zstd")
--compression string compression format to use for index (flate, gzip, lz5, lzw, none, snappy, zlib, zstd) (default "zstd")
--compression-fast use fastest compression level (default is best)
--concurrency int maximum concurrency for scan threads (default 8192)
--disable-buttons disable first/prev/next/last buttons
--exit-on-error shut down webserver on error, instead of just printing error

View File

@ -119,12 +119,25 @@ func getReader(format string, file io.Reader) (io.Reader, error) {
}
func getWriter(format string, file io.WriteCloser) (io.WriteCloser, error) {
switch format {
case "flate":
return flate.NewWriter(file, flate.DefaultCompression)
case "gzip":
switch {
case format == "flate" && CompressionFast:
return flate.NewWriter(file, flate.BestCompression)
case format == "flate":
return flate.NewWriter(file, flate.BestSpeed)
case format == "gzip" && CompressionFast:
return gzip.NewWriterLevel(file, gzip.BestSpeed)
case format == "gzip":
return gzip.NewWriterLevel(file, gzip.BestCompression)
case "lz4":
case format == "lz4" && CompressionFast:
encoder := lz4.NewWriter(file)
err := encoder.Apply(lz4.CompressionLevelOption(lz4.Fast))
if err != nil {
return file, err
}
return encoder, nil
case format == "lz4":
encoder := lz4.NewWriter(file)
err := encoder.Apply(lz4.CompressionLevelOption(lz4.Level9))
@ -133,16 +146,20 @@ func getWriter(format string, file io.WriteCloser) (io.WriteCloser, error) {
}
return encoder, nil
case "lzw":
case format == "lzw":
return lzw.NewWriter(file, lzw.LSB, 8), nil
case "none":
case format == "none":
return file, nil
case "snappy":
case format == "snappy":
return snappy.NewBufferedWriter(file), nil
case "zlib":
return zlib.NewWriter(file), nil
case "zstd":
return zstd.NewWriter(file)
case format == "zlib" && CompressionFast:
return zlib.NewWriterLevel(file, zlib.BestSpeed)
case format == "zlib":
return zlib.NewWriterLevel(file, zlib.BestCompression)
case format == "zstd" && CompressionFast:
return zstd.NewWriter(file, zstd.WithEncoderLevel(zstd.SpeedFastest))
case format == "zstd":
return zstd.NewWriter(file, zstd.WithEncoderLevel(zstd.SpeedBestCompression))
}
return file, ErrInvalidCompression

View File

@ -15,7 +15,7 @@ import (
const (
AllowedCharacters string = `^[A-z0-9.\-_]+$`
ReleaseVersion string = "3.11.0"
ReleaseVersion string = "3.12.0"
)
var (
@ -29,6 +29,7 @@ var (
Code bool
CodeTheme string
Compression string
CompressionFast bool
Concurrency int
DisableButtons bool
ExitOnError bool
@ -136,6 +137,7 @@ func init() {
rootCmd.Flags().BoolVar(&Code, "code", false, "enable support for source code files")
rootCmd.Flags().StringVar(&CodeTheme, "code-theme", "solarized-dark256", "theme for source code syntax highlighting")
rootCmd.Flags().StringVar(&Compression, "compression", "zstd", "compression format to use for index (flate, gzip, lz5, lzw, none, snappy, zlib, zstd)")
rootCmd.Flags().BoolVar(&CompressionFast, "compression-fast", false, "use fastest compression level (default is best)")
rootCmd.Flags().IntVar(&Concurrency, "concurrency", 8192, "maximum concurrency for scan threads")
rootCmd.Flags().BoolVar(&DisableButtons, "disable-buttons", false, "disable first/prev/next/last buttons")
rootCmd.Flags().BoolVar(&ExitOnError, "exit-on-error", false, "shut down webserver on error, instead of just printing error")