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 --case-sensitive use case-sensitive matching for filters
--code enable support for source code files --code enable support for source code files
--code-theme string theme for source code syntax highlighting (default "solarized-dark256") --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) --concurrency int maximum concurrency for scan threads (default 8192)
--disable-buttons disable first/prev/next/last buttons --disable-buttons disable first/prev/next/last buttons
--exit-on-error shut down webserver on error, instead of just printing error --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) { func getWriter(format string, file io.WriteCloser) (io.WriteCloser, error) {
switch format { switch {
case "flate": case format == "flate" && CompressionFast:
return flate.NewWriter(file, flate.DefaultCompression) return flate.NewWriter(file, flate.BestCompression)
case "gzip": 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) 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) encoder := lz4.NewWriter(file)
err := encoder.Apply(lz4.CompressionLevelOption(lz4.Level9)) err := encoder.Apply(lz4.CompressionLevelOption(lz4.Level9))
@ -133,16 +146,20 @@ func getWriter(format string, file io.WriteCloser) (io.WriteCloser, error) {
} }
return encoder, nil return encoder, nil
case "lzw": case format == "lzw":
return lzw.NewWriter(file, lzw.LSB, 8), nil return lzw.NewWriter(file, lzw.LSB, 8), nil
case "none": case format == "none":
return file, nil return file, nil
case "snappy": case format == "snappy":
return snappy.NewBufferedWriter(file), nil return snappy.NewBufferedWriter(file), nil
case "zlib": case format == "zlib" && CompressionFast:
return zlib.NewWriter(file), nil return zlib.NewWriterLevel(file, zlib.BestSpeed)
case "zstd": case format == "zlib":
return zstd.NewWriter(file) 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 return file, ErrInvalidCompression

View File

@ -15,49 +15,50 @@ import (
const ( const (
AllowedCharacters string = `^[A-z0-9.\-_]+$` AllowedCharacters string = `^[A-z0-9.\-_]+$`
ReleaseVersion string = "3.11.0" ReleaseVersion string = "3.12.0"
) )
var ( var (
AdminPrefix string AdminPrefix string
All bool All bool
AllowEmpty bool AllowEmpty bool
Audio bool Audio bool
BinaryPrefix bool BinaryPrefix bool
Bind string Bind string
CaseSensitive bool CaseSensitive bool
Code bool Code bool
CodeTheme string CodeTheme string
Compression string Compression string
Concurrency int CompressionFast bool
DisableButtons bool Concurrency int
ExitOnError bool DisableButtons bool
Fallback bool ExitOnError bool
Filtering bool Fallback bool
Flash bool Filtering bool
Fun bool Flash bool
Handlers bool Fun bool
Ignore bool Handlers bool
IgnoreFile string Ignore bool
Images bool IgnoreFile string
Index bool Images bool
IndexFile string Index bool
Info bool IndexFile string
MaxFileCount int Info bool
MinFileCount int MaxFileCount int
PageLength int MinFileCount int
Port int PageLength int
Prefix string Port int
Profile bool Prefix string
Recursive bool Profile bool
Redact bool Recursive bool
Refresh bool Redact bool
Russian bool Refresh bool
Sorting bool Russian bool
Text bool Sorting bool
Verbose bool Text bool
Version bool Verbose bool
Videos bool Version bool
Videos bool
CompressionFormats = []string{ CompressionFormats = []string{
"flate", "flate",
@ -136,6 +137,7 @@ func init() {
rootCmd.Flags().BoolVar(&Code, "code", false, "enable support for source code files") 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(&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().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().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(&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") rootCmd.Flags().BoolVar(&ExitOnError, "exit-on-error", false, "shut down webserver on error, instead of just printing error")