bytes

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Pad

func Pad(data []byte, paddingSize int) []byte

Pad returns a buffer of the original data with padded trailing 0s of length of given paddingSize

Example
package main

import (
	"bytes"
	"fmt"

	byteUtil "github.com/taubyte/utils/slices/bytes"
)

func main() {
	padSize := 5
	data := []byte("hello world")

	paddedData := byteUtil.Pad(data, padSize)

	data = append(data, make([]byte, padSize)...)
	if !bytes.Equal(data, paddedData) {
		return
	}

	fmt.Println(len(paddedData))
}
Output:

16

func PadLCM

func PadLCM(data []byte, lcm int) []byte

PadLCM returns a buffer with length of the Least Common Multiple of the given lcm value with the original data with padded trailing 0s

Example
package main

import (
	"bytes"
	"fmt"

	byteUtil "github.com/taubyte/utils/slices/bytes"
)

func main() {
	lcm := 5
	data := []byte("hello world")

	paddedData := byteUtil.PadLCM(data, lcm)

	data = append(data, make([]byte, 4)...)
	if !bytes.Equal(data, paddedData) {
		return
	}

	fmt.Println(len(paddedData))
}
Output:

15

func StripPadding

func StripPadding(data []byte) []byte

StripPadding returns a buffer of the data stripped of all trailing 0s

Types

This section is empty.

Jump to

Keyboard shortcuts

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