dataunits

package module
v0.0.0-...-f57cf1e Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: ISC Imports: 7 Imported by: 0

README

Go Data Units

License Go Report Card GoDoc

This is a library that provides utility functions for working with various data units in Go. Primarily for Storage sizes and Memory sizes.

Features

  • Conversion between different data units (bytes, kilobytes, megabytes, etc.)
  • Formatting data sizes for display
  • Parsing data sizes from strings

Usage

To use the library, use the following command:

go get github.com/daegalus/go-dataunits

then import it

import (
  "github.com/daegalus/go-dataunits"
)

Example

package main

import (
 "fmt"
 "github.com/daegalus/go-dataunits"
)

func main() {
 ds, err := dataunits.ParseSize[storage.StorageUnit]("1.5GiB")
 if err != nil {
  fmt.Println("Error parsing size:", err)
  return
 }

 fmt.Println("Parsed size:", ds.Size) // 1.5
 fmt.Println("Parsed size in bytes:", ds.Bytes) // 1610612736.0
 fmt.Println("Parsed Unit in bytes:", ds.Unit) // 1073741824 (GB in bytes)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DataSize

type DataSize[T units.Units] struct {
	Size  float64
	Unit  T
	Bytes float64
}

func ParseSize

func ParseSize[T units.Units](input string) (DataSize[T], error)

func (DataSize[T]) Exabyte

func (ds DataSize[T]) Exabyte() float64

func (DataSize[T]) Exbibyte

func (ds DataSize[T]) Exbibyte() float64

func (DataSize[T]) Gibibyte

func (ds DataSize[T]) Gibibyte() float64

func (DataSize[T]) Gigabyte

func (ds DataSize[T]) Gigabyte() float64

func (DataSize[T]) Kibibyte

func (ds DataSize[T]) Kibibyte() float64

func (DataSize[T]) Kilobyte

func (ds DataSize[T]) Kilobyte() float64

func (DataSize[T]) Mebibyte

func (ds DataSize[T]) Mebibyte() float64

func (DataSize[T]) Megabyte

func (ds DataSize[T]) Megabyte() float64

func (DataSize[T]) Pebibyte

func (ds DataSize[T]) Pebibyte() float64

func (DataSize[T]) Petabyte

func (ds DataSize[T]) Petabyte() float64

func (DataSize[T]) Tebibyte

func (ds DataSize[T]) Tebibyte() float64

func (DataSize[T]) Terabyte

func (ds DataSize[T]) Terabyte() float64

func (DataSize[T]) Yobibyte

func (ds DataSize[T]) Yobibyte() float64

func (DataSize[T]) Yottabyte

func (ds DataSize[T]) Yottabyte() float64

func (DataSize[T]) Zebibyte

func (ds DataSize[T]) Zebibyte() float64

func (DataSize[T]) Zettabyte

func (ds DataSize[T]) Zettabyte() float64

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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