1 | <?php |
||
12 | class FileReader extends InputStreamReader |
||
13 | { |
||
14 | /** |
||
15 | * @var int バッファリングサイズ |
||
16 | */ |
||
17 | private $bufferSize; |
||
18 | |||
19 | /** |
||
20 | * constructor |
||
21 | * @param mixed $file ファイルオブジェクトまたはファイルパス |
||
22 | * @param int $bufferSize バッファリングサイズ |
||
23 | */ |
||
24 | public function __construct($file, int $bufferSize = 8192) |
||
25 | { |
||
26 | parent::__construct(new FileInputStream($file)); |
||
27 | $this->bufferSize = $bufferSize; |
||
28 | } |
||
29 | |||
30 | /** |
||
31 | * ファイルを読み込む |
||
32 | * @return string ファイル内容 |
||
33 | */ |
||
34 | public function read() |
||
35 | { |
||
36 | $out = ""; |
||
37 | while (($data = $this->stream->read($this->bufferSize)) !== null) { |
||
38 | $out .= $data; |
||
39 | } |
||
40 | |||
41 | return $out; |
||
42 | } |
||
43 | } |
||
44 |