Documentation
¶
Index ¶
- Constants
- Variables
- func AtomicWrite(path string, data []byte) error
- func CopyFile(src, dst string) error
- func EnsureDir(path string) error
- func EnsureParentDir(path string) error
- func ExpandPageRanges(ranges []PageRange) []int
- func FileExists(path string) bool
- func FinishProgressBar(bar *progressbar.ProgressBar)
- func FormatError(err error) string
- func FormatFileSize(bytes int64) string
- func FormatPageRanges(pages []int) string
- func GenerateOutputFilename(input, suffix string) string
- func GetFileSize(path string) (int64, error)
- func IsDir(path string) bool
- func IsFileNotFound(err error) bool
- func IsImageFile(path string) bool
- func IsPasswordRequired(err error) bool
- func IsStdinInput(path string) bool
- func IsStdinPiped() bool
- func NewBytesProgressBar(description string, total int64) *progressbar.ProgressBar
- func NewProgressBar(description string, total, threshold int) *progressbar.ProgressBar
- func ParseAndExpandPages(input string) ([]int, error)
- func ParseReorderSequence(spec string, totalPages int) ([]int, error)
- func ReadFromStdin() (path string, cleanup func(), err error)
- func ResolveInputPath(input string) (path string, cleanup func(), err error)
- func ValidatePDFFile(path string) error
- func ValidatePDFFiles(paths []string) error
- func ValidatePageNumbers(pages []int, totalPages int) error
- func WrapError(operation string, file string, err error) error
- func WriteToStdout(path string) error
- type OutputFormat
- type OutputFormatter
- type PDFError
- type PageRange
Constants ¶
const StdinIndicator = "-"
StdinIndicator is the conventional indicator for stdin input.
Variables ¶
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
var ProgressBarTheme = progressbar.Theme{
Saucer: "=",
SaucerHead: ">",
SaucerPadding: " ",
BarStart: "[",
BarEnd: "]",
}
ProgressBarTheme is the default theme for progress bars.
var SupportedImageExtensions = []string{".png", ".jpg", ".jpeg", ".tif", ".tiff"}
SupportedImageExtensions contains all supported image file extensions.
Functions ¶
func AtomicWrite ¶
AtomicWrite writes data to a file atomically by writing to a temp file first
func EnsureParentDir ¶
EnsureParentDir creates the parent directory of a file path if it doesn't exist
func ExpandPageRanges ¶
ExpandPageRanges expands a slice of PageRange to individual page numbers
func FinishProgressBar ¶ added in v1.4.0
func FinishProgressBar(bar *progressbar.ProgressBar)
FinishProgressBar prints a newline after the progress bar if it exists.
func FormatError ¶
FormatError formats an error for display to the user
func FormatFileSize ¶
FormatFileSize formats a file size in bytes to a human-readable string
func FormatPageRanges ¶
FormatPageRanges converts a slice of page numbers back to a compact range string
func GenerateOutputFilename ¶
GenerateOutputFilename generates an output filename based on the input and a suffix
func GetFileSize ¶
GetFileSize returns the size of a file in bytes
func IsFileNotFound ¶
IsFileNotFound checks if an error is a file not found error
func IsImageFile ¶ added in v1.4.0
IsImageFile checks if a file has a supported image extension.
func IsPasswordRequired ¶
IsPasswordRequired checks if an error indicates a password is required
func IsStdinInput ¶ added in v1.4.0
IsStdinInput returns true if the input path indicates stdin.
func IsStdinPiped ¶ added in v1.4.0
func IsStdinPiped() bool
IsStdinPiped returns true if stdin has data piped to it (not a terminal).
func NewBytesProgressBar ¶ added in v1.4.0
func NewBytesProgressBar(description string, total int64) *progressbar.ProgressBar
NewBytesProgressBar creates a progress bar for byte-based progress (e.g., downloads).
func NewProgressBar ¶ added in v1.4.0
func NewProgressBar(description string, total, threshold int) *progressbar.ProgressBar
NewProgressBar creates a consistent progress bar with the given description and total count. Returns nil if total is at or below the threshold for showing progress.
func ParseAndExpandPages ¶
ParseAndExpandPages parses a page range string and returns individual page numbers
func ParseReorderSequence ¶ added in v1.3.1
ParseReorderSequence parses a reorder sequence string and returns the page numbers in order. Supports individual pages (1,3,5), ranges (1-10), special values (end), reverse ranges (10-1), and page duplication (1,2,3,1 repeats page 1 at the end).
func ReadFromStdin ¶ added in v1.4.0
ReadFromStdin reads stdin to a temporary file and returns the path and cleanup function. The caller is responsible for calling the cleanup function when done.
func ResolveInputPath ¶ added in v1.4.0
ResolveInputPath resolves an input path, handling stdin indicator. Returns the actual path to use and a cleanup function. If the input is not stdin, cleanup is a no-op.
func ValidatePDFFile ¶
ValidatePDFFile checks if a file exists and has a .pdf extension
func ValidatePDFFiles ¶
ValidatePDFFiles validates multiple PDF files in parallel
func ValidatePageNumbers ¶
ValidatePageNumbers checks if all page numbers are within the valid range
func WriteToStdout ¶ added in v1.4.0
WriteToStdout writes a file's contents to stdout.
Types ¶
type OutputFormat ¶ added in v1.4.0
type OutputFormat string
OutputFormat represents the output format type.
const ( FormatHuman OutputFormat = "" FormatJSON OutputFormat = "json" FormatCSV OutputFormat = "csv" FormatTSV OutputFormat = "tsv" )
func ParseOutputFormat ¶ added in v1.4.0
func ParseOutputFormat(s string) OutputFormat
ParseOutputFormat parses a string into an OutputFormat.
type OutputFormatter ¶ added in v1.4.0
type OutputFormatter struct {
Format OutputFormat
Writer io.Writer
}
OutputFormatter handles formatted output in various formats.
func NewOutputFormatter ¶ added in v1.4.0
func NewOutputFormatter(format string) *OutputFormatter
NewOutputFormatter creates a new OutputFormatter with the given format.
func (*OutputFormatter) IsStructured ¶ added in v1.4.0
func (f *OutputFormatter) IsStructured() bool
IsStructured returns true if the format is a structured format (JSON, CSV, TSV).
func (*OutputFormatter) Print ¶ added in v1.4.0
func (f *OutputFormatter) Print(data interface{}) error
Print outputs data in the configured format. For JSON, data is marshaled directly. For other formats, data should be a struct or map.
func (*OutputFormatter) PrintTable ¶ added in v1.4.0
func (f *OutputFormatter) PrintTable(headers []string, rows [][]string) error
PrintTable outputs tabular data in the configured format.
type PDFError ¶
PDFError represents a user-friendly error for PDF operations
func NewPDFError ¶
NewPDFError creates a new PDFError