1Rex::FS::File(3)      User Contributed Perl Documentation     Rex::FS::File(3)
2
3
4

NAME

6       Rex::FS::File - File Class
7

DESCRIPTION

9       This is the File Class used by file_write and file_read.
10

SYNOPSIS

12        use Rex::Interface::File;
13        my $fh = Rex::Interface::File->create('Local');
14        $fh->open( '<', 'filename' );
15
16        my $file = Rex::FS::File->new(fh => $fh);
17        $file->read($len);
18        $file->read_all;
19        $file->write($buf);
20        $file->close;
21

CLASS METHODS

23   new
24       This is the constructor. You need to set the filehandle which the
25       object should work on or pass a filename. If you pass a filehandle, it
26       has to be a "Rex::Interface::File::*" object
27
28        my $fh = Rex::Interface::File->create('Local');
29        $fh->open( '<', 'filename' );
30
31        my $file = Rex::FS::File->new(fh => $fh);
32
33       Create a "Rex::FS::File" object with a filename
34
35        # open a local file in read mode
36        my $file = Rex::FS::File->new(
37          filename => 'filename',
38          mode     => 'r', # or '<'
39          type     => 'Local',
40        );
41
42        # or shorter
43        my $file = Rex::FS::File->new( filename => 'filename' );
44
45        # open a local file in write mode
46        my $file = Rex::FS::File->new(
47          filename => 'filename',
48          mode     => 'w', # or '>'
49        );
50
51       Allowed modes:
52
53        <  read
54        r  read
55        >  write
56        w  write
57        >> append
58        a  append
59
60       For allowed "types" see documentation of Rex::Interface::File.
61
62   write($buf)
63       Write $buf into the filehandle.
64
65        $file->write("Hello World");
66
67   seek($offset)
68       Seek to the file position $offset.
69
70       Set the file pointer to the 5th byte.
71
72        $file->seek(5);
73
74   read($len)
75       Read $len bytes out of the filehandle.
76
77        my $content = $file->read(1024);
78
79   read_all
80       Read everything out of the filehandle.
81
82        my $content = $file->read_all;
83
84   close
85       Close the file.
86
87        $file->close;
88
89
90
91perl v5.32.1                      2021-03-06                  Rex::FS::File(3)
Impressum