util

package
v0.2.8 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2024 License: Unlicense Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ZIP = ArchiveType{
		func(w io.Writer) archiveBase {
			zipWriter := zip.NewWriter(w)
			zipWriter.RegisterCompressor(
				zip.Deflate,
				func(w io.Writer) (io.WriteCloser, error) {
					return flate.NewWriter(w, flate.BestCompression)
				})
			return &archiveZip{zipWriter}
		},
		"zip"}
	TGZ = ArchiveType{
		func(w io.Writer) archiveBase {
			if gzWriter, err := gzip.NewWriterLevel(w, gzip.BestCompression); err == nil {
				return &archiveTgz{
					tar.NewWriter(gzWriter),
					gzWriter}
			}
			return nil
		},
		"tgz"}
)

supported archive types

Functions

func CreateArchive

func CreateArchive(
	archiveType ArchiveType,
	contentPath string) (string, string, error)

Creates an archive of the given type with the content from contentPath.

Return values: archivePath, archiveHash, error

func Execute

func Execute(cmdline []string, env ...string) error

func FindInFile

func FindInFile(path string, query string) []string

func ReplaceMultiple

func ReplaceMultiple(text string, replacements map[string]string) string

Types

type ArchiveType

type ArchiveType struct {
	Creator   func(io.Writer) archiveBase
	Extension string
}

type BodyReader

type BodyReader struct {
	io.LimitedReader
}

func BodyFromFile

func BodyFromFile(path string) BodyReader

func BodyFromMap

func BodyFromMap(data map[string]string) BodyReader

func (BodyReader) Length

func (bodyReader BodyReader) Length() int64

Jump to

Keyboard shortcuts

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