forked from mholt/archiver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
brotli.go
42 lines (31 loc) · 872 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
package archiver
import (
"io"
"strings"
"github.com/andybalholm/brotli"
)
func init() {
RegisterFormat(Brotli{})
}
// Brotli facilitates brotli compression.
type Brotli struct {
Quality int
}
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 the stream would be to try decoding
// part of it, and this is not implemented for now
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
}