{"id":20310131,"url":"https://github.com/phpro/resource-stream","last_synced_at":"2025-04-11T15:40:53.272Z","repository":{"id":258056782,"uuid":"873641207","full_name":"phpro/resource-stream","owner":"phpro","description":"A safe OOP wrapper around resource streams","archived":false,"fork":false,"pushed_at":"2025-03-24T16:55:20.000Z","size":82,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-03-25T11:49:21.435Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/phpro.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-16T14:00:21.000Z","updated_at":"2025-03-24T16:54:43.000Z","dependencies_parsed_at":"2024-11-14T17:42:16.587Z","dependency_job_id":null,"html_url":"https://github.com/phpro/resource-stream","commit_stats":null,"previous_names":["phpro/resource-stream"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpro%2Fresource-stream","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpro%2Fresource-stream/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpro%2Fresource-stream/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpro%2Fresource-stream/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phpro","download_url":"https://codeload.github.com/phpro/resource-stream/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248432913,"owners_count":21102465,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-14T17:30:06.168Z","updated_at":"2025-04-11T15:40:53.261Z","avatar_url":"https://github.com/phpro.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Resource Stream\n\nA safe OOP wrapper around resource [streams](https://www.php.net/manual/en/book.stream.php) in PHP:\n\n* No need to worry about streams that have been closed.\n* Instead of returning `false`, detailed exceptions are thrown when something goes wrong.\n* Streams are automatically closed when the object is destructed (with option to opt-out).\n* Handy factory methods for common streams.\n\n## Installation\n\n```bash\ncomposer require phpro/resource-stream\n```\n\n## Usage\n\n```php\nuse Phpro\\ResourceStream\\ResourceStream;\n\n$stream = (new ResourceStream(fopen('php://temp', 'r+')))\n    -\u003ewrite('Hello World')\n    -\u003erewind();\n\n// Various ways to read:\necho $stream-\u003eread();\necho $stream-\u003eread($bufferSize);\necho $stream-\u003ereadLine();\necho $stream-\u003ereadLine($bufferSize, ending: \\PHP_EOL);\necho $stream-\u003egetContents();\n\n// Or in batches (Generator\u003cstring\u003e)\n$cursor = $stream-\u003ereadBatches($bufferSize);\n$cursor = $stream-\u003ereadLines($bufferSize, ending: \\PHP_EOL); \n\n// Get access to PHP's inner resource stream\n$innerStream = $stream-\u003eunwrap();\n\n// Get access to common information:\n$stream-\u003eisOpen();\n$stream-\u003eisEof();\n$stream-\u003euri();\n$stream-\u003esize();\n\n// Possibility to copy contents across streams\n$stream-\u003ecopyTo($anotherStream);\n$stream-\u003ecopyFrom($anotherStream);\n\n// Streams will automatically be closed on destruction.\n// Of course, you can choose to keep it open or close it manually:\n$stream-\u003ekeepAlive();\n$stream-\u003eclose();\n```\n\n## Built-in Streams\n\nThe following streams are available by default:\n\n### CliStream\n\nCan be used to open up CLI `stdin`, `stdout` and `stderr` streams.\n\n```php\nuse Phpro\\ResourceStream\\Factory\\CliStream;\n\n$stdin = CliStream::stdin();\n$stdout = CliStream::stdout();\n$stderr = CliStream::stderr();\n```\n\n### FileStream\n\nValidates if the local file exists and opens it up for you to use.\n\n```php\nuse Phpro\\ResourceStream\\Factory\\FileStream;\n\n$stream = FileStream::create('/path/to/file', FileStream::READ_WRITE_MODE);\n```\n\n### IOStream\n\nCan be used to open up CGI `php://input` and `php://output` streams.\n\n```php\nuse Phpro\\ResourceStream\\Factory\\IOStream;\n\n$input = IOStream::input();\n$output = IOStream::output();\n```\n\n### MemoryStream\n\nCreates an in-memory stream for you to use.\n\n```php\nuse Phpro\\ResourceStream\\Factory\\MemoryStream;\n\n$stream = MemoryStream::create();\n```\n\n### Psr7Stream\n\nCreates a stream from a PSR-7 stream / request / response.\nbefore you can use this stream, you'll need to install the `guzzlehttp/psr-7` package which contains a stream wrapper implementation.\n\n```bash\ncomposer require psr/http-message guzzlehttp/psr-7\n```\n\n```php\nuse Phpro\\ResourceStream\\Factory\\Psr7Stream;\n\n$stream = Psr7Stream::createFromStream($anyPsr7Stream);\n$stream = Psr7Stream::createFromRequest($anyPsr7Request);\n$stream = Psr7Stream::createFromResponse($anyPsr7Response);\n```\n\n### TmpStream\n\nCreates a temporary file and opens it up for you to use.\nAfter the stream is closed, the temporary file will be removed.\n\n```php\nuse Phpro\\ResourceStream\\Factory\\TmpStream;\n\n$stream = TmpStream::create();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphpro%2Fresource-stream","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphpro%2Fresource-stream","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphpro%2Fresource-stream/lists"}