dataSizeKit

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// B 1
	B = &Unit{
		value: 1,
		str:   "B",
	}
	// KB 1024
	KB = &Unit{
		value: 1 << 10,
		str:   "KB",
	}
	// MB 1048576
	MB = &Unit{
		value: 1 << 20,
		str:   "MB",
	}
	// GB 1073741824
	GB = &Unit{
		value: 1 << 30,
		str:   "GB",
	}
	// TB 1099511627776
	TB = &Unit{
		value: 1 << 40,
		str:   "TB",
	}
)

Functions

func ParseString added in v2.0.9

func ParseString(str string) (uint64, error)

ParseString

@param str 同时支持"IEC标准"和"SI标准" @return 第一个返回值的单位: 字节(bytes)

e.g. ("42MB") => 42000000 <nil> ("42 MB") => 42000000 <nil> ("42mib") => 44040192 <nil> ("42 mib") => 44040192 <nil>

func ToReadableStringWithIEC added in v2.0.9

func ToReadableStringWithIEC(s uint64) string

ToReadableStringWithIEC

PS: (1) 采用IEC标准(国际电工委员会;https://blog.csdn.net/bioitee/article/details/120797739). (2) 1KB == 1024 (3) 采用此标准: Windows的文件资源管理器、钉钉(Mac版和Windows版都是)、XManager和Tabby的可视化工具...

@param s 单位: 字节(bytes)

e.g.

(78848) => "77 KiB"

func ToReadableStringWithSI deprecated added in v2.0.9

func ToReadableStringWithSI(s uint64) string

ToReadableStringWithSI

Deprecated: 大部门场景使用IEC标准: ToReadableStringWithIEC().

PS: (1) 采用SI标准(国际单位制;https://blog.csdn.net/bioitee/article/details/120797739). (2) 1KB == 1000 (3) 采用此标准: Mac的访达...

@param s 单位: 字节(bytes)

e.g.

(78848) => "79 kB"

Types

type DataSize

type DataSize struct {
	// 数值
	Number float64
	// 单位
	Unit *Unit
}

func (*DataSize) ConvertToTargetUint

func (size *DataSize) ConvertToTargetUint(targetUnit *Unit) *DataSize

ConvertToTargetUint 单位转换

@param targetUnit 可以为nil,将使用默认单位

func (*DataSize) GetByteValue

func (size *DataSize) GetByteValue() uint64

GetByteValue

@return 单位: B(byte)

func (*DataSize) ToString

func (size *DataSize) ToString(precArgs ...int) string

ToString

@param args 默认(不传参)不对小数位进行处理

func (*DataSize) ToSuitableUint

func (size *DataSize) ToSuitableUint() *DataSize

type Unit

type Unit struct {
	// contains filtered or unexported fields
}

func (*Unit) GetValue

func (su *Unit) GetValue() uint64

func (*Unit) String

func (su *Unit) String() string

Jump to

Keyboard shortcuts

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