Skip to content

Commit 9c33bbe

Browse files
committed
Add gzip support
1 parent 4f964da commit 9c33bbe

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/Flynsarmy/CsvSeeder/CsvSeeder.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,18 @@ private function seedFromCSV($filename, $deliminator = ",")
9191
return FALSE;
9292
}
9393

94+
// check if file is gzipped
95+
$finfo = finfo_open(FILEINFO_MIME_TYPE);
96+
$file_mime_type = finfo_file($finfo, $filename);
97+
finfo_close($finfo);
98+
$gzipped = strcmp($file_mime_type, "application/x-gzip") == 0;
99+
94100
$header = NULL;
95101
$row_count = 0;
96102
$data = array();
103+
$handle = $gzipped ? popen("gzip -cd " . $filename, 'r') : fopen($filename, 'r');
97104

98-
if ( ($handle = fopen($filename, 'r')) !== FALSE )
105+
if ( $handle !== FALSE )
99106
{
100107
while ( ($row = fgetcsv($handle, 0, $deliminator)) !== FALSE )
101108
{

0 commit comments

Comments
 (0)