Private
Public Access
1
0

新增: 云OSS存储集成(七牛云+阿里云)+多桶导航+GBK编码自动转换

This commit is contained in:
2026-05-05 03:18:47 +08:00
parent eb5b85e007
commit b4f4b4627d
34 changed files with 5225 additions and 48 deletions

View File

@@ -0,0 +1,24 @@
package filesystem
import (
"bytes"
"io"
"unicode/utf8"
"golang.org/x/text/encoding/simplifiedchinese"
"golang.org/x/text/transform"
)
// BytesToString 智能编码转换UTF-8 直接返回,否则尝试 GBK → UTF-8
func BytesToString(data []byte) string {
if utf8.Valid(data) {
return string(data)
}
// 尝试 GBK 解码
reader := transform.NewReader(bytes.NewReader(data), simplifiedchinese.GBK.NewDecoder())
decoded, err := io.ReadAll(reader)
if err != nil || !utf8.Valid(decoded) {
return string(data) // 转换失败或结果无效,返回原始内容
}
return string(decoded)
}