/
ascii85.go
88 lines (69 loc) · 1.8 KB
/
ascii85.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package processors
import (
"bytes"
"encoding/ascii85"
"fmt"
"io"
)
// ASCII85Encoding encode string to base64.
type ASCII85Encoding struct{}
func (p ASCII85Encoding) Name() string {
return "ascii85-encode"
}
func (p ASCII85Encoding) Alias() []string {
return []string{"ascii85-encoding", "base85-encode", "b85-encode"}
}
func (p ASCII85Encoding) Transform(data []byte, _ ...Flag) (string, error) {
buf := &bytes.Buffer{}
encoder := ascii85.NewEncoder(buf)
_, err := encoder.Write(data)
if err != nil {
return "", err
}
if err := encoder.Close(); err != nil {
return "", err
}
return buf.String(), nil
}
func (p ASCII85Encoding) Flags() []Flag {
return nil
}
func (p ASCII85Encoding) Title() string {
title := "Ascii85 / Base85 Encoding"
return fmt.Sprintf("%s (%s)", title, p.Name())
}
func (p ASCII85Encoding) Description() string {
return "Encode your text to Ascii85 ( Base85 )"
}
func (p ASCII85Encoding) FilterValue() string {
return p.Title()
}
// ASCII85Decoding encode string to Ascii aka base85.
type ASCII85Decoding struct{}
func (p ASCII85Decoding) Name() string {
return "ascii85-decode"
}
func (p ASCII85Decoding) Alias() []string {
return []string{"ascii85-decoding", "base85-decode", "b85-decode"}
}
func (p ASCII85Decoding) Transform(data []byte, _ ...Flag) (string, error) {
decoder := ascii85.NewDecoder(bytes.NewReader(data))
buf, err := io.ReadAll(decoder)
if err != nil {
return "", err
}
return string(buf), nil
}
func (p ASCII85Decoding) Flags() []Flag {
return nil
}
func (p ASCII85Decoding) Title() string {
title := "Ascii85 / Base85 Decoding"
return fmt.Sprintf("%s (%s)", title, p.Name())
}
func (p ASCII85Decoding) Description() string {
return "Decode your text to Ascii85 ( Base85 ) text"
}
func (p ASCII85Decoding) FilterValue() string {
return p.Title()
}