File: compressors.go

package info (click to toggle)
golang-pault-go-debian 0.16.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 412 kB
  • sloc: makefile: 2
file content (25 lines) | stat: -rw-r--r-- 514 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package hashio // import "pault.ag/go/debian/hashio"

import (
	"fmt"
	"io"

	"compress/gzip"
)

type Compressor func(io.Writer) (io.WriteCloser, error)

func gzipCompressor(in io.Writer) (io.WriteCloser, error) {
	return gzip.NewWriter(in), nil
}

var knownCompressors = map[string]Compressor{
	"gz": gzipCompressor,
}

func GetCompressor(name string) (Compressor, error) {
	if compressor, ok := knownCompressors[name]; ok {
		return compressor, nil
	}
	return nil, fmt.Errorf("No such compressor: '%s'", name)
}