| 12345678910111213141516171819202122232425262728293031323334353637383940414243 | 
							- package gio
 
- import (
 
- 	"io"
 
- 	"os"
 
- 	"path/filepath"
 
- 	"strings"
 
- )
 
- // ReadDir 读取文件夹包含其子文件中的所有文件, 并返回绝对路径
 
- // 当指定 suffix 时则仅查找文件后缀为 suffix 的文件
 
- func ReadDir(path string, suffix ...string) ([]string, error) {
 
- 	file, err := os.ReadDir(filepath.Join(path))
 
- 	if err != nil {
 
- 		return nil, err
 
- 	}
 
- 	fileList := make([]string, 0, 1024)
 
- 	for i := 0; i < len(file); i++ {
 
- 		if len(suffix) > 0 && suffix[0] != "" {
 
- 			if !strings.HasSuffix(file[i].Name(), suffix[0]) {
 
- 				continue
 
- 			}
 
- 		}
 
- 		if file[i].IsDir() {
 
- 			var fs []string
 
- 			fs, err = ReadDir(filepath.Join(path, file[i].Name()), suffix...)
 
- 			if err != nil {
 
- 				return nil, err
 
- 			}
 
- 			fileList = append(fileList, fs...)
 
- 			continue
 
- 		}
 
- 		fileList = append(fileList, filepath.Join(path, file[i].Name()))
 
- 	}
 
- 	return fileList, nil
 
- }
 
- func ReadLimit(r io.Reader, n int64) ([]byte, error) {
 
- 	if n == 0 {
 
- 		n = 4096
 
- 	}
 
- 	return io.ReadAll(io.LimitReader(r, n))
 
- }
 
 
  |