Files
isp-config-service/service/rqlite/internal/rarchive/zip.go
T
txix 7ee7b6749f
Create and publish a Docker image / build-and-push-image (push) Canceled after 0s
2025-12-01 16:45:09: merge [main:8101f9a8c84d0c8c7bd462ac374f4db79dbc5d21];
2025-12-01 16:45:09 +03:00

28 lines
534 B
Go

// nolint
package rarchive
import (
"bytes"
"os"
)
// IsZipFile checks if the file at the given path is a ZIP file
// by verifying the magic number (the first few bytes of the file).
func IsZipFile(path string) bool {
f, err := os.Open(path)
if err != nil {
return false
}
defer f.Close()
// Read the first 4 bytes of the file to check the magic number
buf := make([]byte, 4)
_, err = f.Read(buf)
if err != nil {
return false
}
// ZIP files start with "PK\x03\x04"
return bytes.Equal(buf, []byte("PK\x03\x04"))
}