Skip to content

util #

This module defines a few useful functions used throughout the codebase that don't specifically fit inside a module.

Constants #

const (
	reader_buf_size = 1_1000000
	prefixes        = ['B', 'KB', 'MB', 'GB']
)

fn exit_with_message #

pub fn exit_with_message(code int, msg string)

exit_with_message exits the program with a given status code after having first printed a specific message to STDERR

fn match_array_in_array #

pub fn match_array_in_array[T](a1 []T, a2 []T) int

match_array_in_array[T] returns how many elements of a2 overlap with a1. For example, if a1 = "abcd" & a2 = "cd", the result will be 2. If the match is not at the end of a1, the result is 0.

fn hash_file #

pub fn hash_file(path &string) !string

hash_file returns the sha256 hash of a given file

fn reader_to_writer #

pub fn reader_to_writer(mut reader io.Reader, mut writer io.Writer) !

reader_to_writer tries to consume the entire reader & write it to the writer.

fn pretty_bytes #

pub fn pretty_bytes(bytes int) string

pretty_bytes converts a byte count to human-readable version

fn read_until_separator #

pub fn read_until_separator(mut reader io.Reader, mut res []u8, sep []u8) !

read_until_separator consumes an io.Reader until it encounters some separator array. The data read is stored inside the provided res array.

fn reader_to_file #

pub fn reader_to_file(mut reader io.BufferedReader, length int, path string) !

reader_to_file writes the contents of a BufferedReader to a file

struct Dummy #

pub struct Dummy {
	x int
}

Dummy struct to work around the fact that you can only share structs, maps & arrays