Skip to content

Instantly share code, notes, and snippets.

@pmatseykanets
Last active October 23, 2018 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pmatseykanets/b51146df74739aff2f971a8d7e44c0a3 to your computer and use it in GitHub Desktop.
Save pmatseykanets/b51146df74739aff2f971a8d7e44c0a3 to your computer and use it in GitHub Desktop.
Read the contents of a gzip file from an AWS S3 bucket
<?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