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
|
package coding
import (
"io"
"github.com/dromara/dongle/coding/base85"
)
// ByBase85 encodes by base85.
func (e Encoder) ByBase85() Encoder {
if e.Error != nil {
return e
}
// Streaming encoding mode
if e.reader != nil {
e.dst, e.Error = e.stream(func(w io.Writer) io.WriteCloser {
return base85.NewStreamEncoder(w)
})
return e
}
// Standard encoding mode
if len(e.src) > 0 {
e.dst = base85.NewStdEncoder().Encode(e.src)
}
return e
}
// ByBase85 decodes by base85.
func (d Decoder) ByBase85() Decoder {
if d.Error != nil {
return d
}
// Streaming decoding mode
if d.reader != nil {
d.dst, d.Error = d.stream(func(r io.Reader) io.Reader {
return base85.NewStreamDecoder(r)
})
return d
}
// Standard decoding mode
if len(d.src) > 0 {
d.dst, d.Error = base85.NewStdDecoder().Decode(d.src)
}
return d
}
|