Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce a BinaryFile decoder #32

Merged
merged 1 commit into from
Nov 9, 2023
Merged

Conversation

veewee
Copy link
Contributor

@veewee veewee commented Nov 9, 2023

Q A
Type feature
BC Break no
Fixed issues

Summary

Introduces a BinaryFile preset that extracts file information (like content-type, md5 hash, filename, ...) from the response.
That way, all the information you need is already there and you can focus on storing the file and.

use Phpro\HttpTools\Encoding\Binary\BinaryFile;
use Phpro\HttpTools\Request\Request;
use Phpro\HttpTools\Transport\Presets\BinaryDownloadPreset;

$transport = BinaryDownloadPreset::create($client, $uriBuilder);
$binaryFile = $transport(
    new Request('GET', '/some/file', [], null),
);

assert($binaryFile instanceof BinaryFile);
var_dump(
    $binaryFile->stream(),
    $binaryFile->fileSizeInBytes(),
    $binaryFile->hash(),
    $binaryFile->extension(),
    $binaryFile->mimeType(),
    $binaryFile->fileName(),
);

@veewee veewee added the enhancement New feature or request label Nov 9, 2023
@veewee veewee merged commit 05d1272 into phpro:v2.x Nov 9, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant