forked from PHPOffice/PhpSpreadsheet
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCsvIconv2.php
More file actions
32 lines (28 loc) · 1.09 KB
/
CsvIconv2.php
File metadata and controls
32 lines (28 loc) · 1.09 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
<?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Csv;
use PhpOffice\PhpSpreadsheet\Reader\Csv;
use PhpOffice\PhpSpreadsheet\Reader\Exception as ReaderException;
class CsvIconv2 extends Csv
{
protected function convertNonUtf8(string $filename): void
{
fclose($this->fileHandle);
$filtered = "php://filter/convert.iconv.{$this->inputEncoding}.utf-8/resource=$filename";
$sourceStream = fopen($filtered, 'rb');
if ($sourceStream === false) {
throw new ReaderException("Unable to get contents of $filename"); // @codeCoverageIgnore
}
$fileHandle = fopen('php://memory', 'r+b');
if ($fileHandle === false) {
throw new ReaderException('Unable to open php://memory'); // @codeCoverageIgnore
}
$bytes = stream_copy_to_stream($sourceStream, $fileHandle);
fclose($sourceStream);
if ($bytes === false) {
throw new ReaderException('Unable to copy stream'); // @codeCoverageIgnore
}
$this->fileHandle = $fileHandle;
$this->skipBOM();
}
}