Rex::FS::File(3)
π NAME π
okay bestie, welcome to Rex::FS::File(3) π this is a User Contributed Perl Documentation page, and the manual name is literally Rex::FS::File β it's giving File Class main character energy, no cap.
Rex::FS::File β File Class ποΈβ¨
πΈ DESCRIPTION πΈ
This is the File Class used by file_write and file_read. periodt π
π¦ SYNOPSIS π¦
Here's the whole vibe in code, bestie:
use Rex::Interface::File;
my $fh = Rex::Interface::File->create('Local');
$fh->open( '<', 'filename' );
my $file = Rex::FS::File->new(fh => $fh);
$file->read($len);
$file->read_all;
$file->write($buf);
$file->close;
π CLASS METHODS π
π new β the constructor π
This is the constructor. You need to set the filehandle which the object should work on or pass a filename.
If you pass a filehandle, it has to be a Rex::Interface::File::* object. iykyk π
my $fh = Rex::Interface::File->create('Local');
$fh->open( '<', 'filename' );
my $file = Rex::FS::File->new(fh => $fh);
Create a Rex::FS::File object with a filename β slay:
# open a local file in read mode
my $file = Rex::FS::File->new(
filename => 'filename',
mode => 'r', # or '<'
type => 'Local',
);
# or shorter
my $file = Rex::FS::File->new( filename => 'filename' );
# open a local file in write mode
my $file = Rex::FS::File->new(
filename => 'filename',
mode => 'w', # or '>'
);
Allowed modes, no cap:
< read
r read
> write
w write
>> append
a append
For allowed "types", see the documentation of Rex::Interface::File. πβ¨
β¨ write($buf) β¨
Write $buf into the filehandle. easy peasy:
$file->write("Hello World");
π seek($offset) π
Seek to the file position $offset.
Set the file pointer to the 5th byte. got it? π«Ά
$file->seek(5);
π¦ read($len) π¦
Read $len bytes out of the filehandle. obsessed:
my $content = $file->read(1024);
π read_all π
Read everything out of the filehandle. the whole thing π:
my $content = $file->read_all;
π close π
Close the file. bye bye π:
$file->close;
mwah π β this iconic page is from perl v5.42.3, dated 2023-08-05. bye bestie π«Ά
π¦ where this page comes from
- nixos 26.05: perl5.42.3-Rex 1.14.3
- nixpkgs unstable: perl5.42.3-Rex 1.14.3
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms