diff options
author | feistel <6742251-feistel@users.noreply.gitlab.com> | 2022-06-25 23:09:09 +0300 |
---|---|---|
committer | feistel <6742251-feistel@users.noreply.gitlab.com> | 2022-07-07 13:59:46 +0300 |
commit | 57195a5ae472878c19dae4b6a65bc37a76e992e4 (patch) | |
tree | 65537d02c52e4be9518e4ca6ebf87001ec94b076 /internal/vfs/zip/archive.go | |
parent | 1f9cc507928429fc0a85eaa504bfca692c56ff2a (diff) |
Open files lazily when serving content
Changelog: performance
Diffstat (limited to 'internal/vfs/zip/archive.go')
-rw-r--r-- | internal/vfs/zip/archive.go | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/internal/vfs/zip/archive.go b/internal/vfs/zip/archive.go index 2b04310d..23ad7b2e 100644 --- a/internal/vfs/zip/archive.go +++ b/internal/vfs/zip/archive.go @@ -239,6 +239,25 @@ func (a *zipArchive) Open(ctx context.Context, name string) (vfs.File, error) { } } +// IsCompressed finds the file by name and checks its compression method. If the method is +// zip.Store it means it's not compressed. +// Returns errNotFile for directories or non-regular files. +func (a *zipArchive) IsCompressed(name string) (bool, error) { + file := a.findFile(name) + if file == nil { + if a.findDirectory(name) != nil { + return false, errNotFile + } + return false, os.ErrNotExist + } + + if !file.Mode().IsRegular() { + return false, errNotFile + } + + return file.Method != zip.Store, nil +} + // Lstat finds the file by name inside the zipArchive and returns its FileInfo func (a *zipArchive) Lstat(ctx context.Context, name string) (os.FileInfo, error) { file := a.findFile(name) |