base64

package module
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 25, 2021 License: MIT Imports: 4 Imported by: 20

README

base64

build-img pkg-img reportcard-img coverage-img

Faster base64 encoding for Go, based on Turbo-Base64.

Features

  • Drop-in replacement of encoding/base64.
    • except for error messages and ignoring \r and \n in decoder.
  • up to 3 times faster than encoding/base64.
  • Dependency-free.

Install

Go version 1.16+

go get github.com/cristalhq/base64

How to use

Replace import statement from encoding/base64 to github.com/cristalhq/base64

-import "encoding/base64"
+import "github.com/cristalhq/base64"

Benchmarks

go1.17 linux/amd64, Intel i7-7700

std/Encode           685.3 ns/op      0 B/op   0 allocs/op
std/EncodeToString   951.8 ns/op   2048 B/op   2 allocs/op
std/Decode           803.9 ns/op      0 B/op   0 allocs/op
std/DecodeString     1061 ns/op    1792 B/op   2 allocs/op

own/Encode           217.8 ns/op      0 B/op   0 allocs/op
own/EncodeToString   353.2 ns/op   1024 B/op   1 allocs/op
own/Decode           426.0 ns/op      0 B/op   0 allocs/op
own/DecodeString     598.7 ns/op    768 B/op   1 allocs/op

go1.17 darwin/arm64, Apple M1

std/Encode           413.0 ns/op       0 B/op  0 allocs/op
std/EncodeToString   608.3 ns/op    2048 B/op  2 allocs/op
std/Decode           372.5 ns/op       0 B/op  0 allocs/op
std/DecodeString     570.2 ns/op    1792 B/op  2 allocs/op

own/Encode           146.7 ns/op       0 B/op  0 allocs/op
own/EncodeToString   246.4 ns/op    1024 B/op  1 allocs/op
own/Decode           222.8 ns/op       0 B/op  0 allocs/op
own/DecodeString     303.1 ns/op     768 B/op  1 allocs/op

Fuzzing

Documentation

See these docs.

License

MIT License.

Documentation

Overview

based on https://github.com/powturbo/Turbo-Base64

Index

Constants

This section is empty.

Variables

View Source
var (
	StdEncoding    = NewEncoding(stdLutSe, true)
	RawStdEncoding = NewEncoding(stdLutSe, false)
	URLEncoding    = NewEncoding(urlLutSe, true)
	RawURLEncoding = NewEncoding(urlLutSe, false)
)
View Source
var ErrWrongData = errors.New("wrong base64 data")

Functions

This section is empty.

Types

type Encoding

type Encoding struct {
	// contains filtered or unexported fields
}

func NewEncoding

func NewEncoding(lutSe [64]byte, pad bool) *Encoding

func (*Encoding) Decode

func (e *Encoding) Decode(dst []byte, src []byte) (int, error)

func (*Encoding) DecodeString

func (e *Encoding) DecodeString(src string) ([]byte, error)

func (*Encoding) DecodeStringToString

func (e *Encoding) DecodeStringToString(src string) (string, error)

func (*Encoding) DecodeToBytes

func (e *Encoding) DecodeToBytes(src []byte) ([]byte, error)

func (*Encoding) DecodeToString

func (e *Encoding) DecodeToString(src []byte) (string, error)

func (*Encoding) DecodedLen

func (e *Encoding) DecodedLen(n int) int

func (*Encoding) Encode

func (e *Encoding) Encode(dst []byte, src []byte)

func (*Encoding) EncodeString

func (e *Encoding) EncodeString(src string) []byte

func (*Encoding) EncodeStringToString

func (e *Encoding) EncodeStringToString(src string) string

func (*Encoding) EncodeToBytes

func (e *Encoding) EncodeToBytes(src []byte) []byte

func (*Encoding) EncodeToString

func (e *Encoding) EncodeToString(src []byte) string

func (*Encoding) EncodedLen

func (e *Encoding) EncodedLen(n int) int

Directories

Path Synopsis
fuzz module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL