-
Notifications
You must be signed in to change notification settings - Fork 0
/
brotli.go
44 lines (33 loc) · 876 Bytes
/
brotli.go
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package compressor
import (
"io"
"strings"
"github.com/andybalholm/brotli"
)
// Brotli facilitates brotli compression.
type Brotli struct {
Quality int
}
func init() {
RegisterFormat(Brotli{})
}
func (Brotli) Name() string {
return ".br"
}
func (br Brotli) Match(filename string, stream io.Reader) (MatchResult, error) {
var mr MatchResult
// match filename
if strings.Contains(strings.ToLower(filename), br.Name()) {
mr.ByName = true
}
// brotli does not have well-defined file headers.
// The best way to match a stream would be to try to decode part of it,
// and that has not yet been implemented
return mr, nil
}
func (br Brotli) OpenWriter(w io.Writer) (io.WriteCloser, error) {
return brotli.NewWriterLevel(w, br.Quality), nil
}
func (Brotli) OpenReader(r io.Reader) (io.ReadCloser, error) {
return io.NopCloser(brotli.NewReader(r)), nil
}