Documentation
¶
Overview ¶
Package command provides interfaces for the shell commands and programs on the host.
Index ¶
- Constants
- Variables
- func CopyFile(sl *slog.Logger, src, dst string) error
- func ImagesDelete(unid string, dirs ...string) error
- func ImagesPixelate(ctx context.Context, sl *slog.Logger, unid string, dirs ...string) error
- func Lookup(file string) (string, error)
- func LookupS(ctx context.Context, name, flag, match string) error
- func LookupUnrar(ctx context.Context) error
- func OptimizePNG(ctx context.Context, sl *slog.Logger, src string) error
- func ProgInfos(ctx context.Context) [n]archive.ProgInfo
- func Run(ctx context.Context, sl *slog.Logger, name string, arg ...string) ([]byte, error)
- type Align
- type Crop
- type Dirs
- func (ds Dirs) BinTextImager(ctx context.Context, sl *slog.Logger, srcBinary, unid string) error
- func (ds Dirs) DizDeferred(sl *slog.Logger, srcDIZ, unid string) error
- func (ds Dirs) PictureImager(ctx context.Context, sl *slog.Logger, srcImage, unid string) error
- func (ds Dirs) TextDeferred(ctx context.Context, sl *slog.Logger, srcText, unid string) error
- func (ds Dirs) TextImager(ctx context.Context, sl *slog.Logger, src, unid string, amigaFont bool) error
- func (ds Dirs) Thumbs(ctx context.Context, sl *slog.Logger, unid string, generate Generate) error
- type Generate
- type Runner
- type Text
- type Thumb
Constants ¶
const ( HWZip = "hwzip" // Hwzip the zip decompression command for files using obsolete methods. Arc = "arc" // Arc is the arc decompression command. Arj = "arj" // Arj is the arj decompression command. BSDTar = "bsdtar" // BSDTar is the tar decompression command. Cab = "gcab" // Cab is the gcab decompression command for Microsoft Cabinet. Lha = "lha" // Lha is the lha/lzh decompression command. Lsar = "lsar" // Lsar is The Unarchive list command usable on multiple types. Unar = "unar" // Unar is The Unarchiver decompression command usable on multiple types. Unrar = "unrar" // Unrar is the rar decompression command. Unzip = "unzip" // Unzip is the zip decompression command. Zip7 = "7zz" // Zip7 is the 7-Zip decompression command. Ansilove = "ansilove" // Ansilove is the ansilove text to image command. Cwebp = "cwebp" // Cwebp is the Google create webp command. Gif2webp = "gif2webp" // Gif2webp is the Google gif to webp command. Ilbmtoppm = "ilbmtoppm" // ilbmtoppm belongs to Netpdm for ILBM image conversion. Magick = "magick" // Magick is the ImageMagick v7+ command. Optipng = "optipng" // Optipng is the PNG optimizer command. Pamscale = "pamscale" // Pamscale is used by Netpdm for ILBM image conversion. )
const (
ANSICap = 350_000 // ANSICap is the maximum file size in bytes for an ANSI encoded text file.
)
const (
CmdTimeout = 10 * time.Second
)
Variables ¶
var ( ErrAlign = errors.New("command: invalid align choice") ErrCrop = errors.New("command: invalid crop choice") ErrThumb = errors.New("command: invalid thumb choice") ErrIsAnsi = errors.New("command: text is ansi encoded, cannot crop") ErrIsEmpty = errors.New("command: file is empty") ErrIsFile = errors.New("command: directory path points to a file") ErrNoImages = errors.New("command: no images found") ErrNoMatch = errors.New("command: no match value is present") ErrNoSupport = errors.New("command: file format has no support") ErrUnknownImg = errors.New("command: file is not a known image format") ErrValue = errors.New("command: argument is empty") ErrVersion = errors.New("command: application version mismatch") )
var Infos = [...]string{
"HWZip ver 2+",
"archive utility ver 5+",
"arj32 ver 3+",
"BSDTar 3+",
"gcab ver 1.6+",
"Lhasa command line LHA tool",
"The Unarchiver v1.10+",
"The Unarchiver v1.10+",
"UNRAR freeware (c) Alexander Roshal",
"UnZip Info-ZIP ver 6+",
"7-Zip ver 24+",
"ansilove/c ver 4+",
"Google WebP ver 1+",
"Google GIF to WebP ver 1+",
"ILBM image Netpdm converter",
"ImageMagick ver 7+",
"OptiPNG optimizer ver 0.7+",
"Netpdm image scaler",
}
Infos returns details for the list of the execute command names used by the application.
var Lookups = [...]string{ HWZip, Arc, Arj, BSDTar, Cab, Lha, Lsar, Unar, Unrar, Unzip, Zip7, Ansilove, Cwebp, Gif2webp, Ilbmtoppm, Magick, Optipng, Pamscale, }
Lookups returns a list of the execute command names used by the application.
Functions ¶
func ImagesDelete ¶ added in v0.10.0
ImagesDelete removes images matching the unid from the specified directories. The unid is the unique identifier shared across preview and thumbnail variants. Returns ErrNoImages if no matching files were found and removed.
func ImagesPixelate ¶ added in v0.10.0
ImagesPixelate converts images matching unid across the specified directories into pixelated versions in-place.
func Lookup ¶ added in v1.14.0
Lookup returns an error if the command is not found in the system path.
func LookupS ¶ added in v1.14.0
LookupS returns an error when the match string is not found in the named command output.
func LookupUnrar ¶
LookupUnrar returns an error if the name Alexander Roshal is not found in the unrar version output.
func OptimizePNG ¶
OptimizePNG optimizes the src PNG image in-place using optipng. It is safe to call within a deferred function.
Types ¶
type Align ¶ added in v0.10.0
type Align int
Align is args type that represents the alignment of the thumbnail image.
const ( Top Align = iota // Top uses the top alignment of the preview image Middle // Middle uses the center alignment of the preview image Bottom // Bottom uses the bottom alignment of the preview image Left // Left uses the left alignment of the preview image Right // Right uses the right alignment of the preview image )
type Crop ¶ added in v0.10.0
type Crop int
Crop is an args type that represents the crop position of the preview image.
type Dirs ¶
type Dirs struct {
Download dir.Directory // Download is the directory path for the file downloads.
Preview dir.Directory // Preview is the directory path for the image previews.
Thumbnail dir.Directory // Thumbnail is the directory path for the image thumbnails.
Extra dir.Directory // Extra is the directory path for the extra files.
}
Dirs points to the download, preview, thumbnail, and extra directories.
func (Dirs) BinTextImager ¶ added in v1.9.15
BinTextImager converts a binary text source file into a PNG preview using Ansilove, then processes the generated PNG through the standard text imager pipeline.
func (Dirs) DizDeferred ¶ added in v1.5.1
DizDeferred copies a FILE_ID.DIZ text file into the extra directory.
func (Dirs) PictureImager ¶ added in v0.10.0
PictureImager creates both a preview image and a thumbnail image using the srcImage.
Thumbnails are generated as .webp or .png files, while the preview image format depends on the input format (.png, .jpeg, .avif, .webp, etc.).
func (Dirs) TextDeferred ¶ added in v1.2.2
TextDeferred creates a thumbnail (if one does not exist) and copies the source text file into the extra directory.
func (Dirs) TextImager ¶ added in v0.10.0
func (ds Dirs) TextImager(ctx context.Context, sl *slog.Logger, src, unid string, amigaFont bool) error
TextImager generates two images based on the text file provided by the src path. The provided unid must be a valid universal unique identifier.
Note that TextImager uses ansilove which doesn't support modern Unicode, this includes the common UTF-8 encoding or multibyte characters like emojis.
If the amigaFont is set to true, a Commodore Amiga Tapaz font is used to represent the text, otherwise an IBM VGA font is used. The amigaFont also displays less rows of text due to the Topaz font being taller.
type Generate ¶ added in v1.14.0
type Generate int
Generate is the type of thumbnail image to create.
type Runner ¶ added in v1.14.0
type Text ¶ added in v1.14.0
type Text struct {
UUID string // unique universal ID used as the base filename for the output
MaxRows int // maximum number of rows to crop
MaxCols int // maximum number of to crop, or leave as 0 to use the default of 80
UTF8 bool // when true, MaxCols will crop to Unicode rune count instead of ASCII characters
}
func (Text) Crop ¶ added in v1.14.0
Crop reads the src text file and writes the number of MaxRows (lines) of text to a new file. The new file is stored in the same directory as the src but is given file name of UUID appended with a ".txt" extension. The text is truncated to MaxCols (runes or characters per line), but any leading empty lines are ignored.
If MaxRows is 0, a default value of 29 is used. If MaxCols is set to 0, a default of 80 is used. Both defaults allow for a 400x400 pixel thumbnail to be generated.
- When successful the full path to the new file with the cropped text is returned.
- If unsuccessful the src path is returned.
- If a large number of ANSI sequences are detected then an ErrIsAnsi error is returned.