Skip to content

Commit

Permalink
Update compress.go
Browse files Browse the repository at this point in the history
  • Loading branch information
vlssu committed Apr 25, 2024
1 parent 17e18f4 commit ca1cccd
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions server/filesystem/compress.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand Down Expand Up @@ -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

Check failure on line 128 in server/filesystem/compress.go

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu-22.04, 1.21.8, linux, amd64)

undefined: archiverext.NewFileFS

Check failure on line 128 in server/filesystem/compress.go

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu-22.04, 1.21.8, linux, arm64)

undefined: archiverext.NewFileFS

Check failure on line 128 in server/filesystem/compress.go

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu-22.04, 1.22.1, linux, amd64)

undefined: archiverext.NewFileFS

Check failure on line 128 in server/filesystem/compress.go

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu-22.04, 1.22.1, linux, arm64)

undefined: archiverext.NewFileFS
}
return archiverext.FileFS{File: f, Compression: ff}, nil
// Use NewFileFS constructor to create FileFS instance
return archiverext.NewFileFS(f, ff, filepath.Base(p)), nil

Check failure on line 131 in server/filesystem/compress.go

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu-22.04, 1.21.8, linux, amd64)

undefined: archiverext.NewFileFS

Check failure on line 131 in server/filesystem/compress.go

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu-22.04, 1.21.8, linux, arm64)

undefined: archiverext.NewFileFS

Check failure on line 131 in server/filesystem/compress.go

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu-22.04, 1.22.1, linux, amd64)

undefined: archiverext.NewFileFS

Check failure on line 131 in server/filesystem/compress.go

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu-22.04, 1.22.1, linux, arm64)

undefined: archiverext.NewFileFS
}
}
_ = f.Close()
Expand Down

0 comments on commit ca1cccd

Please sign in to comment.