//go:build (amd64 || arm64) && !purego// +build amd64 arm64// +build !puregopackage base64import ()// An Encoding is a radix 64 encoding/decoding scheme, defined by a// 64-character alphabet.typeEncodingstruct {encfunc(dst []byte, src []byte, lut *int8) (int, int)enclut [encLutSize]int8decfunc(dst []byte, src []byte, lut *int8) (int, int)declut [decLutSize]int8base *base64.Encoding}// WithPadding creates a duplicate Encoding updated with a specified padding// character, or NoPadding to disable padding. The padding character must not// be contained in the encoding alphabet, must not be '\r' or '\n', and must// be no greater than '\xFF'.func ( Encoding) ( rune) *Encoding { .base = .base.WithPadding()return &}// Strict creates a duplicate encoding updated with strict decoding enabled.// This requires that trailing padding bits are zero.func ( Encoding) () *Encoding { .base = .base.Strict()return &}// Encode encodes src using the defined encoding alphabet.// This will write EncodedLen(len(src)) bytes to dst.func ( *Encoding) (, []byte) {iflen() >= minEncodeLen && .enc != nil { , := .enc(, , &.enclut[0]) = [:] = [:] } .base.Encode(, )}// Encode encodes src using the encoding enc, writing// EncodedLen(len(src)) bytes to dst.func ( *Encoding) ( []byte) string { := make([]byte, .base.EncodedLen(len())) .Encode(, )returnstring()}// EncodedLen calculates the base64-encoded byte length for a message// of length n.func ( *Encoding) ( int) int {return .base.EncodedLen()}// Decode decodes src using the defined encoding alphabet.// This will write DecodedLen(len(src)) bytes to dst and return the number of// bytes written.func ( *Encoding) (, []byte) ( int, error) {var , intiflen() >= minDecodeLen && .dec != nil { , = .dec(, , &.declut[0]) = [:] = [:] } , = .base.Decode(, ) += return}// DecodeString decodes the base64 encoded string s, returns the decoded// value as bytes.func ( *Encoding) ( string) ([]byte, error) { := unsafebytes.BytesOf() := make([]byte, .base.DecodedLen(len())) , := .Decode(, )return [:], }// DecodedLen calculates the decoded byte length for a base64-encoded message// of length n.func ( *Encoding) ( int) int {return .base.DecodedLen()}
The pages are generated with Goldsv0.6.7. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.