File::Utils
File::Utils
Table of Contents
NAME
File::Utils
AUTHOR
Francis Grizzly Smit ([email protected])
VERSION
0.1.2
TITLE
File::Utils
SUBTITLE
A Raku module for converting various File system properties to symbolic form.
COPYRIGHT
LGPL V3.0+ LICENSE
Introduction
A Raku module for converting various File system properties to symbolic form. For instance symbolic-perms(…) will give you the .rwxr-xr-x type representation of the file type and permissions like used by ls and exa. And format-bytes(…) will convert the file size from bytes B to TiB, GiB etc.
CorruptFile
CorruptFile is an exception class to be used if a corrupt file is encountered.
class CorruptFile is Exception is export {
has Str:D $.msg = 'Error: File is Corrupt';
method message( --> Str:D) {
$!msg;
}
}symbolic-perms(…)
A function for producing the .rwxrwxrwx form of a files type and permissions like that used by ls and exa. It also supports colourising and syntax highlighting of the perms.
sub symbolic-perms(IO::Path $path,
Bool:D :$colour is copy = False,
Bool:D :$syntax = False,
Bool:D :$highlighted = False,
Bool:D :$cond = False,
Str:D :$highlight-fg-colour = t.color(255, 0, 0),
Str:D :$fg-colour0 = t.color(255, 0, 0),
Str:D :$fg-colour1 = t.color(255, 0, 0) --> Str:D) is export {Where
$pathIs the path of the file/directory to describe the perms for.$colourIf True colour the perms.$syntaxIf true syntax highlight the perms.$highlightedIf true set the text colour to$highlight-fg-colour.$condIf not highlighted and True set the text colour to$fg-color0else set text to$fg-color1.$highlight-fg-colourColour to set the text to if$highlighted.$fg-colour0Colour to set the text to if not$highlightedand$cond.$fg-colour1Colour to set the text to if not$highlightedand not$cond.
NB: Only recognises directory, link and regular file just now.
format-bytes(…)
Format a number in bytes into KiB, MiB, GiB, TiB, …… also appends the GiB, TiB designator.
sub format-bytes(Int:D $bytes, Int:D :$width = 5,
Int:D :$precision = 1 --> Str:D) is exportuid2username(…)
A function to convert a numeric uid into a username, will only work on a typical *nix file system requires /etc/passwd to exist, and be readable. Will fail if these conditions are not true.
sub uid2username(UInt:D $uid --> Str:D) is exportgid2groupname(…)
A function to convert a numeric gid into a groupname, will only work on a typical *nix file system requires /etc/group to exist, and be readable. Will fail if these conditions are not true.
sub gid2groupname(UInt:D $gid --> Str:D) is export