package FileAccess;
use strict;
use warnings;

sub new {
    my($self, $file) = @_;
    my $o = {};
    bless $o;
    $o->{"file"} = $file;
    $o->{"pozice"} = 0; 
    return $o;
}

sub zapis {
    my($self, $text) = @_;
    my $f = open FILE, ">", $self->{"file"} or return;
    print FILE $text;
    close FILE;
    return 1;
}

sub pripis {
    my($self, $text) = @_;
    my $f = open FILE, ">>", $self->{"file"} or return;
    print FILE $text;
    close FILE;
    return 1;
}

sub nastavPozici {
    my($self, $pozice) = @_;
    $self->{"pozice"} = $pozice;
}

sub cti {
    my($self, $pocet_znaku) = @_;
    my $precteno;
    my $f = open FILE, $self->{"file"} or return;
    seek FILE, $self->{"pozice"}, 0;
    read FILE, $precteno, $pocet_znaku;
    $self->{"pozice"} += $pocet_znaku;
    return $precteno;
    close $f;
}

1;