Last active
October 23, 2018 16:47
-
-
Save pmatseykanets/b51146df74739aff2f971a8d7e44c0a3 to your computer and use it in GitHub Desktop.
Read the contents of a gzip file from an AWS S3 bucket
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$file = Storage::disk('s3')->readStream('bucket/file.csv.gz'); | |
// gzip format ZLIB_ENCODING_GZIP | |
// ['window' => 15 + 16] | |
// auto-detect ZLIB_ENCODING_ANY | |
// ['window' => 15 + 32] | |
// See https://github.com/php/php-src/blob/master/ext/zlib/tests/zlib_filter_inflate2.phpt | |
stream_filter_append($file, 'zlib.inflate', STREAM_FILTER_READ, ['window' => 15 + 32]); | |
while (! feof($file) { | |
$record = fgetcsv($file); | |
// Do something | |
} | |
fclose($file); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment