utils

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 16, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ZipMagicBytes = []byte{0x50, 0x4B, 0x03, 0x04}

ZipMagicBytes are the first 4 bytes of a ZIP file

Functions

func AddFileToZip

func AddFileToZip(zipData []byte, filename string, content []byte) ([]byte, error)

AddFileToZip adds or updates a file in a zip archive

func CompareZipContents

func CompareZipContents(zipData1, zipData2 []byte) (bool, error)

CompareZipContents compares two zip files by computing and comparing their hashes Excludes metadata.toml from comparison to focus on actual content

func ComputeFileSHA256

func ComputeFileSHA256(filePath string) (string, error)

ComputeFileSHA256 computes the SHA256 hash of a file

func ComputeFileSHA512

func ComputeFileSHA512(filePath string) (string, error)

ComputeFileSHA512 computes the SHA512 hash of a file

func ComputeSHA256

func ComputeSHA256(data []byte) string

ComputeSHA256 computes the SHA256 hash of data

func ComputeSHA512

func ComputeSHA512(data []byte) string

ComputeSHA512 computes the SHA512 hash of data

func ComputeZipHash

func ComputeZipHash(zipData []byte) ([]byte, error)

ComputeZipHash computes an MD5 hash of all files in a zip archive Files are hashed individually, then combined in alphabetical order by filename

func CreateZip

func CreateZip(sourceDir string) ([]byte, error)

CreateZip creates a zip archive from a directory

func EnsureDir

func EnsureDir(path string) error

EnsureDir ensures that a directory exists, creating it if necessary

func ExpandTilde

func ExpandTilde(path string) (string, error)

ExpandTilde expands a tilde (~) at the beginning of a path to the user's home directory

func ExtractZip

func ExtractZip(zipData []byte, targetDir string) error

ExtractZip extracts a zip file to a target directory

func FileExists

func FileExists(path string) bool

FileExists checks if a file exists

func GetClaudeDir

func GetClaudeDir() (string, error)

GetClaudeDir returns the path to the .claude directory for asset installation This is where global assets are installed

func GetConfigDir

func GetConfigDir() (string, error)

GetConfigDir returns the path to the sx config directory Uses platform-specific config directories: - Linux: ~/.config/sx (or $XDG_CONFIG_HOME/sx) - macOS: ~/Library/Application Support/sx - Windows: %AppData%/sx

func GetConfigFile

func GetConfigFile() (string, error)

GetConfigFile returns the path to the config.json file

func IsDirectory

func IsDirectory(path string) bool

IsDirectory checks if a path is a directory

func IsZipFile

func IsZipFile(data []byte) bool

IsZipFile checks if data starts with ZIP magic bytes

func ListZipFiles

func ListZipFiles(zipData []byte) ([]string, error)

ListZipFiles returns a list of all files in a zip archive

func NormalizePath

func NormalizePath(path string) (string, error)

NormalizePath normalizes a file path, expanding tilde and cleaning it

func ReadZipFile

func ReadZipFile(zipData []byte, filename string) ([]byte, error)

ReadZipFile reads a specific file from a zip archive without extracting

func RemoveFileFromZip

func RemoveFileFromZip(zipData []byte, filename string) ([]byte, error)

RemoveFileFromZip removes a file from a zip archive

func ReplaceFileInZip

func ReplaceFileInZip(zipData []byte, filename string, content []byte) ([]byte, error)

ReplaceFileInZip replaces an existing file in a zip archive This is an alias for AddFileToZip which already handles replacement

func URLHash

func URLHash(url string) string

URLHash computes a short hash of a URL for directory naming

func VerifyHash

func VerifyHash(data []byte, algorithm, expected string) error

VerifyHash verifies that data matches the expected hash

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL