internal

package
v0.0.0-...-847e583 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Copyright 2022 Michal Vyskocil. All rights reserved. Use of this source code is governed by a MIT license that can be found in the LICENSE file.

Index

Constants

View Source
const (
	Block     Byte = 512              // b
	KiloByte       = 1000             // kB
	KibiByte       = 1024             // K/KiB
	MegaByte       = 1000 * KiloByte  // MB
	MebiByte       = 1024 * KibiByte  // M/MiB
	GigaByte       = 1000 * MegaByte  // GB
	GibiByte       = 1024 * MebiByte  // G/GiB
	TeraByte       = 1000 * GigaByte  // TB
	TebiByte       = 1024 * GibiByte  // T/TiB
	PetaByte       = 1000 * TeraByte  // PB
	PebiByte       = 1024 * TebiByte  // P/PiB
	ExaByte        = 1000 * PetaByte  // ZB
	ExbiByte       = 1024 * PebiByte  // Z/ZiB
	ZettaByte      = 1000 * ExaByte   // ZB
	ZebiByte       = 1024 * ExbiByte  // Z/ZiB
	YottaByte      = 1000 * ZettaByte // YB
	YobiByte       = 1024 * ZebiByte  // Y/YiB
)

Byte may have a multiplier suffix: b 512, kB 1000, K 1024, MB 1000*1000, M 1024*1024, GB 1000*1000*1000, G 1024*1024*1024, and so on for T, P, E, Z, Y. Binary prefixes can be used, too: KiB=K, MiB=M, and so on. see https://man7.org/linux/man-pages/man1/head.1.html

Variables

View Source
var (
	ErrEmpty                = errors.New("empty")
	ErrInvalidNextCharacter = errors.New("expected number or decimal separator")
	ErrOverflow             = errors.New("overflow")
	ErrNoDigits             = errors.New("no digits")
)
View Source
var ByteSuffixes = map[string]float64{
	"b":   float64(Block),
	"kB":  float64(KiloByte),
	"K":   float64(KibiByte),
	"KiB": float64(KibiByte),
	"MB":  float64(MegaByte),
	"M":   float64(MebiByte),
	"MiB": float64(MebiByte),
	"GB":  float64(GigaByte),
	"G":   float64(GibiByte),
	"GiB": float64(GibiByte),
	"TB":  float64(TeraByte),
	"T":   float64(TebiByte),
	"TiB": float64(TebiByte),
	"PB":  float64(PetaByte),
	"P":   float64(PebiByte),
	"PiB": float64(PebiByte),
	"EB":  float64(ExaByte),
	"E":   float64(ExbiByte),
	"EiB": float64(ExbiByte),
	"ZB":  float64(ZettaByte),
	"Z":   float64(ZebiByte),
	"ZiB": float64(ZebiByte),
	"YB":  float64(YottaByte),
	"Y":   float64(YobiByte),
	"YiB": float64(YobiByte),
}

Functions

func PMap

func PMap[T any, U any](ctx context.Context, limit uint, slice []T, mapFunc MapFunc[T, U]) ([]U, error)

Types

type Byte

type Byte Unit

Byte is a size of disk/memory/buffer capacities

func ParseByte

func ParseByte(s string) (Byte, error)

ParseByte parses a byte definition. A byte string is a possibly signed sequence of decimal numbers, each with optional fraction and a unit suffix, such as "300K", "-1.5MiB" or "1TB45GB". Valid time units are "b" block 512, "kB" kilobyte 1000, "K", "KiB" kibibyte 1024 and so on for M, G, T, P, E, Z, Y

func (*Byte) Set

func (b *Byte) Set(value string) error

func (Byte) Type

func (b Byte) Type() string

type MapFunc

type MapFunc[T any, U any] func(context.Context, T) (U, error)

type RunFiles

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

RunFiles is a helper run gonix commands with inputs from more files failure in file opening does not break the loop, but returns exit code 1 "" or "-" are treated as stdin

func NewRunFiles

func NewRunFiles(files []string, stdio unix.StandardIO, fun func(context.Context, unix.StandardIO, int, string) error) RunFiles

func (RunFiles) Do

func (l RunFiles) Do(ctx context.Context) error

func (RunFiles) DoThreads

func (l RunFiles) DoThreads(ctx context.Context, threads uint) error

DoThreads runs individual tasks concurrently via PMap. Each command writes to the memory buffer first, so probably best to be used for a compute intensive operations like cksum is. As it uses PMap, outputs are in the same order as inputs.

type Unit

type Unit float64

Unit represents the units with multiplier suffixes. Is defined as float64 to support things like YottaByte and so. It is generalized version of time.Duration

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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