Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 110 lines (94 sloc) 2.359 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
--TEST--
File stream EOF behavior
--SKIPIF--
<?php if(!extension_loaded("rar")) print "skip"; ?>
--FILE--
<?php

$a = RarArchive::open(dirname(__FILE__) . "/multi.part1.rar");
$a2 = RarArchive::open(dirname(__FILE__) . "/4mb.rar");

function echoeof($stream) {
echo feof($stream)?"At eof":"Not at eof";
echo "\n";
}

echo "* First fread is given file size:\n";
$stream = $a->getEntry("file1.txt")->getStream();
echoeof($stream);
var_dump(fread($stream, 18));
echoeof($stream);
var_dump(fread($stream, 1));
echoeof($stream);

echo "\n* First fread is given size - 1:\n";
$stream = $a->getEntry("file1.txt")->getStream();
echoeof($stream);
var_dump(fread($stream, 17));
echoeof($stream);
var_dump(fread($stream, 1));
echoeof($stream);
var_dump(fread($stream, 1));
echoeof($stream);

echo "\n* First fread is given size + 1:\n";
$stream = $a->getEntry("file1.txt")->getStream();
echoeof($stream);
var_dump(fread($stream, 19));
echoeof($stream);

echo "\n* Read is aligned with dictionary, buffer and file size:\n";
$stream = $a2->getEntry("4mb.txt")->getStream();
echoeof($stream);
var_dump(strlen(fread($stream, 4194304)));
echoeof($stream);
var_dump(strlen(fread($stream, 1)));
echoeof($stream);

echo "\n* Read is dictionary, buffer and file size - 1:\n";
$stream = $a2->getEntry("4mb.txt")->getStream();
echoeof($stream);
var_dump(strlen(fread($stream, 4194303)));
echoeof($stream);
var_dump(strlen(fread($stream, 1)));
echoeof($stream);
var_dump(strlen(fread($stream, 1)));
echoeof($stream);

echo "\n* Read is dictionary, buffer and file size + 1:\n";
$stream = $a2->getEntry("4mb.txt")->getStream();
echoeof($stream);
var_dump(strlen(fread($stream, 4194305)));
echoeof($stream);

echo "\n";
echo "Done.\n";
--EXPECTF--
* First fread is given file size:
Not at eof
string(18) "contents of file 1"
Not at eof
string(0) ""
At eof

* First fread is given size - 1:
Not at eof
string(17) "contents of file "
Not at eof
string(1) "1"
Not at eof
string(0) ""
At eof

* First fread is given size + 1:
Not at eof
string(18) "contents of file 1"
At eof

* Read is aligned with dictionary, buffer and file size:
Not at eof
int(4194304)
Not at eof
int(0)
At eof

* Read is dictionary, buffer and file size - 1:
Not at eof
int(4194303)
Not at eof
int(1)
Not at eof
int(0)
At eof

* Read is dictionary, buffer and file size + 1:
Not at eof
int(4194304)
At eof

Done.
Something went wrong with that request. Please try again.