GoFrame gfile-文件大小
文件大小
Size
func Size(path string) int64
func ExampleSize() {
// init
var (
fileName = "gflie_example.txt"
tempDir = gfile.TempDir("gfile_example_size")
tempFile = gfile.Join(tempDir, fileName)
)
// write contents
gfile.PutContents(tempFile, "0123456789")
fmt.Println(gfile.Size(tempFile))
// Output:
// 10
}
SizeFormat
func SizeFormat(path string) string
func ExampleSizeFormat() {
// init
var (
fileName = "gflie_example.txt"
tempDir = gfile.TempDir("gfile_example_size")
tempFile = gfile.Join(tempDir, fileName)
)
// write contents
gfile.PutContents(tempFile, "0123456789")
fmt.Println(gfile.SizeFormat(tempFile))
// Output:
// 10.00B
}
ReadableSize
- 说明:获取给定路径容量大小,并格式化人类易读的硬盘容量格式
- 格式:
func ReadableSize(path string) string
func ExampleReadableSize() {
// init
var (
fileName = "gflie_example.txt"
tempDir = gfile.TempDir("gfile_example_size")
tempFile = gfile.Join(tempDir, fileName)
)
// write contents
gfile.PutContents(tempFile, "01234567899876543210")
fmt.Println(gfile.ReadableSize(tempFile))
// Output:
// 20.00B
}
StrToSize
func StrToSize(sizeStr string) int64
func ExampleStrToSize() {
size := gfile.StrToSize("100MB")
fmt.Println(size)
// Output:
// 104857600
}
FormatSize
- 说明:大小整形转换为硬盘容量大小字符串`K、m、g、t、p、e、b`
- 格式:
func FormatSize(raw int64) string
func ExampleFormatSize() {
sizeStr := gfile.FormatSize(104857600)
fmt.Println(sizeStr)
sizeStr0 := gfile.FormatSize(1024)
fmt.Println(sizeStr0)
sizeStr1 := gfile.FormatSize(999999999999999999)
fmt.Println(sizeStr1)
// Output:
// 100.00M
// 1.00K
// 888.18P
}