An implementation of the php-extended/php-api-endpoint-http-interface that unzip data on the fly when the responses are queried
This package is auto-updated.
Last update: 2023-08-15 15:50:19 UTC
An implementation of the php-extended/php-api-endpoint-http-interface that unzip data on the fly when the responses are queried.
The installation of this library is made via composer and the autoloading of all classes of this library is made through their autoloader.
composer.pharfrom their website.
- Then run the following command to install this library as dependency :
php composer.phar php-extended/php-api-endpoint-http-gzip ^6
This library needs multiple conditions for it to work :
- First, The request must contain an
X-Php-Download-Fileheader pointing to a possible valid file in an existing and writeable directory. This is where the downloaded file will be downloaded by the http client.
- Second, an http client that supports the
X-Php-Download-Fileheader to write the body of the http request in that file.
- Third, the http client must set an
X-Request-Header-X-Php-Download-Fileheader in the response that points to that same file. If it does not, it may set an
- Fourth, the http client must give a Response with a stream that points to this file.
What this endpoint does is, for each time a file is requested, it will try to
uncompress it in the same directory as it is, with a new name. It will replace
X-Php-Download-File headers in the request to point to the new uncompressed
file, and will change the stream of the response with a new stream pointing to
the new file. The old file that was requested at the
header in the request is deleted if the uncompress operation is successful.
/* @var $httpEndpoint \PhpExtended\Endpoint\EndpointInterface */ $gzipEndpoint = new GzipHttpEndpoint($httpEndpoint); $stream = $gzipEndpoint->httpGet($gzipEndpoint->createUri('https://example.com/path/to/file.gz'), [ 'X-Php-Download-File' => '/tmp/file.gz', ]); /* @var $stream \Psr\Http\Message\StreamInterface */
Once you're finished with the stream you can delete the file (using the metadata
of the stream you can find the file name).
$gzipEndpoint->httpGetResponse() you will get
the http response instead of only the stream and can get the file path with
MIT (See license file).