diff --git a/os/gfile/gfile_z_example_cache_test.go b/os/gfile/gfile_z_example_cache_test.go index 0bca09bf4..735e15047 100644 --- a/os/gfile/gfile_z_example_cache_test.go +++ b/os/gfile/gfile_z_example_cache_test.go @@ -29,7 +29,7 @@ func ExampleGetContentsWithCache() { // read contents fmt.Println(gfile.GetContentsWithCache(tempFile)) - // Output: + // May Output: // goframe example content // new goframe example content } diff --git a/os/gfile/gfile_z_example_scan_test.go b/os/gfile/gfile_z_example_scan_test.go index eadb498e1..7021b5dea 100644 --- a/os/gfile/gfile_z_example_scan_test.go +++ b/os/gfile/gfile_z_example_scan_test.go @@ -22,7 +22,7 @@ func ExampleScanDir() { gfile.PutContents(tempSubFile, "goframe example content") // scans directory recursively - list, _ := gfile.ScanDir(tempDir, "gflie_example.txt,sub_dir", true) + list, _ := gfile.ScanDir(tempDir, "*", true) for _, v := range list { fmt.Println(gfile.Basename(v)) } @@ -49,7 +49,7 @@ func ExampleScanDirFile() { gfile.PutContents(tempSubFile, "goframe example content") // scans directory recursively exclusive of directories - list, _ := gfile.ScanDirFile(tempDir, "gflie_example.txt,sub_dir", true) + list, _ := gfile.ScanDirFile(tempDir, "*", true) for _, v := range list { fmt.Println(gfile.Basename(v)) } @@ -75,7 +75,7 @@ func ExampleScanDirFunc() { gfile.PutContents(tempSubFile, "goframe example content") // scans directory recursively - list, _ := gfile.ScanDirFunc(tempDir, "gflie_example.txt,sub_dir", true, func(path string) string { + list, _ := gfile.ScanDirFunc(tempDir, "*", true, func(path string) string { // ignores some files if gfile.Basename(path) == "gflie_example.txt" { return "" @@ -110,7 +110,7 @@ func ExampleScanDirFileFunc() { gfile.PutContents(tempSubFile, "goframe example content") // scans directory recursively exclusive of directories - list, _ := gfile.ScanDirFileFunc(tempDir, "gflie_example.txt,gflie_example_ignores.txt,sub_dir", true, func(path string) string { + list, _ := gfile.ScanDirFileFunc(tempDir, "*", true, func(path string) string { // ignores some files if gfile.Basename(path) == "gflie_example_ignores.txt" { return "" diff --git a/os/gfile/gfile_z_example_size_test.go b/os/gfile/gfile_z_example_size_test.go index 39aefd33e..2ae557ce4 100644 --- a/os/gfile/gfile_z_example_size_test.go +++ b/os/gfile/gfile_z_example_size_test.go @@ -7,51 +7,51 @@ import ( ) func ExampleSize() { - tempDir := gfile.TempDir("gfile_example_size0") - if gfile.Exists(tempDir) { - gfile.Remove(tempDir) - } - gfile.Mkdir(tempDir) - size := gfile.Size(tempDir) - if size == 0 { // Why does every directory have a size 4096 bytes (4K)? - size = 4096 - } - fmt.Println(size) + // 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: - // 4096 + // 10 } func ExampleSizeFormat() { - tempDir := gfile.TempDir("gfile_example_sizeF0B") - if gfile.Exists(tempDir) { - gfile.Remove(tempDir) - } - gfile.Mkdir(tempDir) - sizeStr := gfile.SizeFormat(tempDir) - if sizeStr == "0.00B" { // Why does every directory have a size 4096 bytes (4K)? - sizeStr = "4.00K" - } - fmt.Println(sizeStr) + // 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: - // 4.00K + // 10.00B } func ExampleReadableSize() { - tempDir := gfile.TempDir("gfile_example_sizeR0B") - if gfile.Exists(tempDir) { - gfile.Remove(tempDir) - } - gfile.Mkdir(tempDir) - sizeStr := gfile.ReadableSize(tempDir) - if sizeStr == "0.00B" { // Why does every directory have a size 4096 bytes (4K)? - sizeStr = "4.00K" - } - fmt.Println(sizeStr) + // 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: - // 4.00K + // 20.00B } func ExampleStrToSize() { @@ -65,10 +65,13 @@ func ExampleStrToSize() { 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 }