Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
koriym committed Jun 9, 2024
1 parent 108ad5a commit 75a1774
Showing 1 changed file with 1 addition and 43 deletions.
44 changes: 1 addition & 43 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,47 +6,5 @@
[![codecov](https://codecov.io/gh/bearsunday/BEAR.Streamer/branch/1.x/graph/badge.svg?token=eh3c9AF4Mr)](https://codecov.io/gh/koriym/BEAR.Streamer)
[![Type Coverage](https://shepherd.dev/github/bearsunday/BEAR.Streamer/coverage.svg)](https://shepherd.dev/github/bearsunday/BEAR.Streamer)
[![Continuous Integration](https://github.com/bearsunday/BEAR.Streamer/actions/workflows/continuous-integration.yml/badge.svg)](https://github.com/bearsunday/BEAR.Streamer/actions/workflows/continuous-integration.yml)
Assign stream resource to resource-body.

```php
class Image extends ResourceObject
{
use StreamTransferInject;

public function onGet(string $name = 'inline image') : ResourceObject
{
$fp = fopen(__DIR__ . '/BEAR.jpg', 'r');
stream_filter_append($fp, 'convert.base64-encode'); // image base64 format
$this->body = [
'name' => $name,
'image' => $fp
];

return $this;
}
}
```

Or assign entire body.

```php
class Download extends ResourceObject
{
use StreamTransferInject;

public $headers = [
'Content-Type' => 'image/jpeg',
'Content-Disposition' => 'attachment; filename="image.jpg"'
];

public function onGet() : ResourceObject
{
$fp = fopen(__DIR__ . '/BEAR.jpg', 'r');
$this->body = $fp;

return $this;
}
}
```

Http body will not be output at once with "echo", Instead streamed with low memory consumption.
See [Stream Response](https://bearsunday.github.io/manuals/1.0/en/stream.html) on the BEAR.Sunday manual site.

0 comments on commit 75a1774

Please sign in to comment.