util

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFileNotFound     = errors.New("file not found")
	ErrNotPDF           = errors.New("not a valid PDF file")
	ErrInvalidPages     = errors.New("invalid page specification")
	ErrPasswordRequired = errors.New("password required")
	ErrWrongPassword    = errors.New("incorrect password")
	ErrCorruptPDF       = errors.New("PDF file is corrupted")
	ErrOutputExists     = errors.New("output file already exists")
)

Common error types

Functions

func AtomicWrite

func AtomicWrite(path string, data []byte) error

AtomicWrite writes data to a file atomically by writing to a temp file first

func CopyFile

func CopyFile(src, dst string) error

CopyFile copies a file from src to dst

func EnsureDir

func EnsureDir(path string) error

EnsureDir creates a directory if it doesn't exist

func EnsureParentDir

func EnsureParentDir(path string) error

EnsureParentDir creates the parent directory of a file path if it doesn't exist

func ExpandPageRanges

func ExpandPageRanges(ranges []PageRange) []int

ExpandPageRanges expands a slice of PageRange to individual page numbers

func FileExists

func FileExists(path string) bool

FileExists checks if a file exists

func FormatError

func FormatError(err error) string

FormatError formats an error for display to the user

func FormatFileSize

func FormatFileSize(bytes int64) string

FormatFileSize formats a file size in bytes to a human-readable string

func FormatPageRanges

func FormatPageRanges(pages []int) string

FormatPageRanges converts a slice of page numbers back to a compact range string

func GenerateOutputFilename

func GenerateOutputFilename(input, suffix string) string

GenerateOutputFilename generates an output filename based on the input and a suffix

func GetFileSize

func GetFileSize(path string) (int64, error)

GetFileSize returns the size of a file in bytes

func IsDir

func IsDir(path string) bool

IsDir checks if a path is a directory

func IsFileNotFound

func IsFileNotFound(err error) bool

IsFileNotFound checks if an error is a file not found error

func IsPasswordRequired

func IsPasswordRequired(err error) bool

IsPasswordRequired checks if an error indicates a password is required

func ParseAndExpandPages

func ParseAndExpandPages(input string) ([]int, error)

ParseAndExpandPages parses a page range string and returns individual page numbers

func ValidatePDFFile

func ValidatePDFFile(path string) error

ValidatePDFFile checks if a file exists and has a .pdf extension

func ValidatePDFFiles

func ValidatePDFFiles(paths []string) error

ValidatePDFFiles validates multiple PDF files

func ValidatePageNumbers

func ValidatePageNumbers(pages []int, totalPages int) error

ValidatePageNumbers checks if all page numbers are within the valid range

func WrapError

func WrapError(operation string, file string, err error) error

WrapError wraps an error with additional context

Types

type PDFError

type PDFError struct {
	Operation string
	File      string
	Cause     error
	Hint      string
}

PDFError represents a user-friendly error for PDF operations

func NewPDFError

func NewPDFError(operation, file string, cause error) *PDFError

NewPDFError creates a new PDFError

func (*PDFError) Error

func (e *PDFError) Error() string

func (*PDFError) Unwrap

func (e *PDFError) Unwrap() error

func (*PDFError) WithHint

func (e *PDFError) WithHint(hint string) *PDFError

WithHint adds a hint to a PDFError

type PageRange

type PageRange struct {
	Start int
	End   int
}

PageRange represents a range of pages

func ParsePageRanges

func ParsePageRanges(input string) ([]PageRange, error)

ParsePageRanges parses a page range string like "1-5,7,10-12" Returns a slice of PageRange structs

Jump to

Keyboard shortcuts

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