Rex::FS::File(3)

πŸ“¦ version 1.14.3, in nixos 26.05, nixpkgs unstable

πŸŽ€ 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