Files
podman/vendor/go.podman.io/common/pkg/strongunits/config.go
Paul Holzinger dbfddb82cb vendor: update go.podman.io/{common,image,storage}
Update to the latest tags to make sure they all work correctly.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2025-09-03 17:46:02 +02:00

66 lines
1.2 KiB
Go

package strongunits
// supported units
// B represents bytes.
type B uint64
// KiB represents KiB.
type KiB uint64
// MiB represents MiB.
type MiB uint64
// GiB represents GiB.
type GiB uint64
const (
// kibToB is the math convert from bytes to KiB.
kibToB = 1 << 10
// mibToB is the math to convert from bytes to MiB.
mibToB = 1 << 20
// gibToB s the math to convert from bytes to GiB.
gibToB = 1 << 30
)
// StorageUnits is an interface for converting disk/memory storage
// units amongst each other.
type StorageUnits interface {
ToBytes() B
}
// ToBytes is a pass-through function for bytes.
func (b B) ToBytes() B {
return b
}
// ToBytes converts KiB to bytes.
func (k KiB) ToBytes() B {
return B(k * kibToB)
}
// ToBytes converts MiB to bytes.
func (m MiB) ToBytes() B {
return B(m * mibToB)
}
// ToBytes converts GiB to bytes.
func (g GiB) ToBytes() B {
return B(g * gibToB)
}
// ToKiB converts any StorageUnit type to KiB.
func ToKiB(b StorageUnits) KiB {
return KiB(b.ToBytes() >> 10)
}
// ToMib converts any StorageUnit type to MiB.
func ToMib(b StorageUnits) MiB {
return MiB(b.ToBytes() >> 20)
}
// ToGiB converts any StorageUnit type to GiB.
func ToGiB(b StorageUnits) GiB {
return GiB(b.ToBytes() >> 30)
}