diff --git a/server/filesystem/compress.go b/server/filesystem/compress.go index 25476c1e..190af3a8 100644 --- a/server/filesystem/compress.go +++ b/server/filesystem/compress.go @@ -54,13 +54,6 @@ func (fs *Filesystem) CompressFiles(dir string, paths []string) (ufs.FileInfo, e return f.Stat() } -type FileFS struct { - File io.ReadCloser - Compression archiver.Compression - // 添加 FileName 字段来单独存储文件名 - FileName string -} - // decodeGBK 解码 GBK 编码的字符串 func decodeGBK(input string) (string, error) { decoder := simplifiedchinese.GBK.NewDecoder() @@ -71,6 +64,23 @@ func decodeGBK(input string) (string, error) { return decoded, nil } +// FileFS represents a file system for a compressed file. +type FileFS struct { + File ufs.File + Compression archiver.Compression + // Add FileName field + FileName string +} + +// NewFileFS returns a new instance of a FileFS. +func NewFileFS(file ufs.File, compression archiver.Compression, fileName string) *FileFS { + return &FileFS{ + File: file, + Compression: compression, + FileName: fileName, + } +} + // archiverFileSystem 使用 archiver 根据文件的格式返回文件系统 func (fs *Filesystem) archiverFileSystem(ctx context.Context, p string) (iofs.FS, error) { f, err := fs.unixFS.Open(p) @@ -114,9 +124,11 @@ func (fs *Filesystem) archiverFileSystem(ctx context.Context, p string) (iofs.FS if err != nil { return nil, err } - return archiverext.FileFS{File: f, Compression: ff, FileName: gbkName}, nil + // Use NewFileFS constructor to create FileFS instance + return archiverext.NewFileFS(f, ff, gbkName), nil } - return archiverext.FileFS{File: f, Compression: ff}, nil + // Use NewFileFS constructor to create FileFS instance + return archiverext.NewFileFS(f, ff, filepath.Base(p)), nil } } _ = f.Close()