diskspace

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package diskspace reports free and total bytes of the filesystem holding a path, on Unix and Windows, and formats byte counts for display.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Free

func Free(path string) (int64, error)

Free reports the bytes free at path that an unprivileged user could write, per statfs's Bavail field (not Bfree, which includes root-reserved blocks).

func HumanBytes

func HumanBytes(bytes int64) string

HumanBytes renders bytes the same way web/src/lib/format.ts's own formatBytes does (binary units, one decimal place under 10 of a unit, none at or above), so a value read from Free and one read from the dashboard's own API response read the same regardless of which side rendered it. Negative bytes render as "0 B" rather than a negative unit, since this only ever wraps a real filesystem free-space value.

Example
package main

import (
	"fmt"

	"github.com/GLINCKER/levelrail/kit/diskspace"
)

func main() {
	fmt.Println(diskspace.HumanBytes(1536))
	fmt.Println(diskspace.HumanBytes(5 << 30))
}
Output:
1.5 KiB
5.0 GiB

func Usage

func Usage(path string) (free, total int64, err error)

Usage reports free (Bavail) and total bytes of the filesystem holding path.

Types

This section is empty.

Jump to

Keyboard shortcuts

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