util

package
v0.0.0-...-4e3d77a Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const CACHE_DIRNAME string = "cache"
View Source
const IMAGE_DIRNAME string = "images"
View Source
const MIN_CHAN_SIZE = 256
View Source
const RATE_LIMIT_DELAY_SEC = 2

Do not query a single site too quickly.

View Source
const UNSAFE_JOIN_DELIM = "\u2012"

A figure dash ("‒").

View Source
const UNSAFE_JOIN_REPLACE_CHAR = "-"

A hyphen (dash).

Variables

This section is empty.

Functions

func AbsWithSlash

func AbsWithSlash(path string) (string, error)

Call filepath.Abs(), but add a trailing slash for dirs. Checking for a dir requires a stat and implies the existance of the dirent.

func CBZInfo

func CBZInfo(path string) (int, string, error)

Assume that the archive is a CBZ, and get the number of imaeges and the first image (as a thumbnail).

func CopyFile

func CopyFile(source string, dest string) error

func CopyImage

func CopyImage(relSource string, relDest string) (string, error)

func FetchImage

func FetchImage(url string) (string, string, error)

Returns (abspath, relpath, error).

func Get

func Get(url string) ([]byte, error)

func GetImagePath

func GetImagePath(relpath string) string

func GetWithCache

func GetWithCache(url string) ([]byte, error)

func IsDir

func IsDir(path string) bool

func IsPrefixPath

func IsPrefixPath(target string, prefix string) (bool, error)

Is |prefix| a prefix of |target|. (Same paths counts as a prefix.)

func Max

func Max[T constraints.Ordered](a T, b T) T

func Min

func Min[T constraints.Ordered](a T, b T) T

func PathExists

func PathExists(path string) bool

Tell if a path exists.

func PoolMap

func PoolMap[T any, R any](values []T, consumer PoolConsumer[T, R]) ([]R, error)

func ToJSON

func ToJSON(data any) (string, error)

func UnsafeJoin

func UnsafeJoin(values []string) string

Join together strings by first replacing any instances of UNSAFE_JOIN_DELIM with UNSAFE_JOIN_REPLACE_CHAR, and then joining the strings together with UNSAFE_JOIN_DELIM. This could mean that UnsafeSplit(UnsafeJoin(values)) != values. However, we will use a delimiter that is rare and typically represented visually the same as the replacement character.

func UnsafeSplit

func UnsafeSplit(text string) []string

func WriteImage

func WriteImage(data []byte, relpath string) error

func ZipExtractFile

func ZipExtractFile(zipPath string, filename string) ([]byte, error)

func ZipImageCount

func ZipImageCount(path string) (int, error)

Count the number of image files in a zip archive.

func ZipListFilenames

func ZipListFilenames(path string) ([]string, error)

Types

type ParallelPool

type ParallelPool[T any, R any] struct {
	// contains filtered or unexported fields
}

A pool should only be accessed from a single thread.

func NewParallelPool

func NewParallelPool[T any, R any](consumer PoolConsumer[T, R]) *ParallelPool[T, R]

func NewParallelPoolWithSize

func NewParallelPoolWithSize[T any, R any](numValues int, consumer PoolConsumer[T, R]) *ParallelPool[T, R]

func (*ParallelPool[T, R]) AddWork

func (this *ParallelPool[T, R]) AddWork(value T)

Will panic if ParallelPool.NoMoreWork() is called first. Should be called on the same thread as NoMoreWork.

func (*ParallelPool[T, R]) Close

func (this *ParallelPool[T, R]) Close()

func (*ParallelPool[T, R]) GetResult

func (this *ParallelPool[T, R]) GetResult() (R, bool, error)

The returned boolean will be false when the output channel has been closed and there is no work work on it (i.e., all work is consumed).

func (*ParallelPool[T, R]) NoMoreWork

func (this *ParallelPool[T, R]) NoMoreWork()

Should be called on the same thread as AddWork.

type PoolConsumer

type PoolConsumer[T any, R any] func(value T) (R, error)

Jump to

Keyboard shortcuts

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