Documentation
¶
Index ¶
- Variables
- func AddFileToZip(zipData []byte, filename string, content []byte) ([]byte, error)
- func CleanupMarkdownSpacing(content string) string
- func CompareZipContents(zipData1, zipData2 []byte) (bool, error)
- func ComputeFileSHA256(filePath string) (string, error)
- func ComputeFileSHA512(filePath string) (string, error)
- func ComputeSHA256(data []byte) string
- func ComputeSHA512(data []byte) string
- func ComputeZipHash(zipData []byte) ([]byte, error)
- func CreateZip(sourceDir string) ([]byte, error)
- func CreateZipFromContent(filename string, content []byte) ([]byte, error)
- func EnsureDir(path string) error
- func ExpandTilde(path string) (string, error)
- func ExtractZip(zipData []byte, targetDir string) error
- func FileExists(path string) bool
- func GetClaudeDir() (string, error)
- func GetConfigDir() (string, error)
- func GetConfigFile() (string, error)
- func HasContentFiles(zipData []byte) (bool, error)
- func IsDirectory(path string) bool
- func IsZipFile(data []byte) bool
- func ListZipFiles(zipData []byte) ([]string, error)
- func NormalizePath(path string) (string, error)
- func ReadZipFile(zipData []byte, filename string) ([]byte, error)
- func RemoveFileFromZip(zipData []byte, filename string) ([]byte, error)
- func RemoveMarkdownSections(content string, headingsToRemove []string) string
- func ReplaceFileInZip(zipData []byte, filename string, content []byte) ([]byte, error)
- func Slugify(s string) string
- func URLHash(url string) string
- func VerifyHash(data []byte, algorithm, expected string) error
- type MarkdownSection
Constants ¶
This section is empty.
Variables ¶
var ZipMagicBytes = []byte{0x50, 0x4B, 0x03, 0x04}
ZipMagicBytes are the first 4 bytes of a ZIP file
Functions ¶
func AddFileToZip ¶
AddFileToZip adds or updates a file in a zip archive
func CleanupMarkdownSpacing ¶ added in v0.9.0
CleanupMarkdownSpacing reduces multiple consecutive blank lines to a maximum of two
func CompareZipContents ¶
CompareZipContents compares two zip files by computing and comparing their hashes Excludes metadata.toml from comparison to focus on actual content
func ComputeFileSHA256 ¶
ComputeFileSHA256 computes the SHA256 hash of a file
func ComputeFileSHA512 ¶
ComputeFileSHA512 computes the SHA512 hash of a file
func ComputeSHA256 ¶
ComputeSHA256 computes the SHA256 hash of data
func ComputeSHA512 ¶
ComputeSHA512 computes the SHA512 hash of data
func ComputeZipHash ¶
ComputeZipHash computes an MD5 hash of all files in a zip archive Files are hashed individually, then combined in alphabetical order by filename
func CreateZipFromContent ¶ added in v0.5.5
CreateZipFromContent creates a zip archive containing a single file with the given content
func ExpandTilde ¶
ExpandTilde expands a tilde (~) at the beginning of a path to the user's home directory
func ExtractZip ¶
ExtractZip extracts a zip file to a target directory
func GetClaudeDir ¶
GetClaudeDir returns the path to the .claude directory for asset installation This is where global assets are installed
func GetConfigDir ¶
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 ¶
GetConfigFile returns the path to the config.json file
func HasContentFiles ¶ added in v0.10.0
HasContentFiles returns true if the zip contains files beyond metadata.toml. This is used to distinguish packaged assets (with server code) from config-only assets.
func ListZipFiles ¶
ListZipFiles returns a list of all files in a zip archive
func NormalizePath ¶
NormalizePath normalizes a file path, expanding tilde and cleaning it
func ReadZipFile ¶
ReadZipFile reads a specific file from a zip archive without extracting
func RemoveFileFromZip ¶
RemoveFileFromZip removes a file from a zip archive
func RemoveMarkdownSections ¶ added in v0.9.0
RemoveMarkdownSections removes specified sections from markdown content
func ReplaceFileInZip ¶
ReplaceFileInZip replaces an existing file in a zip archive This is an alias for AddFileToZip which already handles replacement
func Slugify ¶ added in v0.9.0
Slugify converts a string to a valid asset name. The result contains only lowercase alphanumeric characters and hyphens, matching the asset name validation pattern ^[a-zA-Z0-9_-]+$.
Transformations:
- Convert to lowercase
- Replace spaces and underscores with hyphens
- Remove all other special characters
- Collapse consecutive hyphens
- Trim leading/trailing hyphens
func VerifyHash ¶
VerifyHash verifies that data matches the expected hash
Types ¶
type MarkdownSection ¶ added in v0.9.0
type MarkdownSection struct {
Heading string // The heading text (without ## prefix)
Content string // The section content (including any sub-headings)
Level int // Heading level (2 for ##, 3 for ###, etc.)
}
MarkdownSection represents a parsed section from a markdown file
func ParseMarkdownSections ¶ added in v0.9.0
func ParseMarkdownSections(content string) []MarkdownSection
ParseMarkdownSections extracts ## sections from markdown content. Returns empty slice for empty content or content without ## headings. Sub-headings (###, ####, etc.) are included in their parent section's content.