<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package Archive::Cpio::FileHandle_with_pushback;

sub new {
    my ($class, $F) = @_;
    bless { F =&gt; $F, already_read =&gt; '' }, $class;
}

sub pushback {
    my ($FHwp, $s) = @_;

    $FHwp-&gt;{already_read} .= $s;
}

sub read {
    my ($FHwp, $size) = @_;

    $size or return;

    $size =~ /^\d+$/ or die "bad size $size\n";

    my $tmp = '';

    if ($FHwp-&gt;{already_read}) {
        $tmp = substr($FHwp-&gt;{already_read}, 0, $size);
        substr($FHwp-&gt;{already_read}, 0, $size) = '';
        $size -= length($tmp);
    }
    read($FHwp-&gt;{F}, $tmp, $size, length($tmp)) == $size or die "unexpected end of file while reading (got $tmp)\n";
    $tmp;
}

sub read_ahead {
    my ($FHwp, $size) = @_;

    my $s = $FHwp-&gt;read($size);
    $FHwp-&gt;pushback($s);
    $s;
}

1;
</pre></body></html>