{"id":20789522,"url":"https://github.com/kusabi/stream","last_synced_at":"2025-07-15T11:36:00.474Z","repository":{"id":56577672,"uuid":"196522922","full_name":"kusabi/stream","owner":"kusabi","description":"A PSR-7 and PSR-17 conforming stream wrapper library for PHP","archived":false,"fork":false,"pushed_at":"2020-10-31T13:18:34.000Z","size":24,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-18T10:27:18.651Z","etag":null,"topics":["php","psr","psr-17","psr-7","stream","wrapper"],"latest_commit_sha":null,"homepage":"","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/kusabi.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":".github/contributing.md","funding":null,"license":null,"code_of_conduct":".github/code_of_conduct.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-07-12T06:37:03.000Z","updated_at":"2020-10-31T13:18:36.000Z","dependencies_parsed_at":"2022-08-15T21:20:25.734Z","dependency_job_id":null,"html_url":"https://github.com/kusabi/stream","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kusabi%2Fstream","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kusabi%2Fstream/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kusabi%2Fstream/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kusabi%2Fstream/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kusabi","download_url":"https://codeload.github.com/kusabi/stream/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243135356,"owners_count":20241949,"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":["php","psr","psr-17","psr-7","stream","wrapper"],"created_at":"2024-11-17T15:24:39.592Z","updated_at":"2025-03-12T00:28:31.255Z","avatar_url":"https://github.com/kusabi.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Stream wrapper\n\n![Tests](https://github.com/kusabi/stream/workflows/tests/badge.svg)\n[![codecov](https://codecov.io/gh/kusabi/stream/branch/main/graph/badge.svg)](https://codecov.io/gh/kusabi/stream)\n[![Licence Badge](https://img.shields.io/github/license/kusabi/stream.svg)](https://img.shields.io/github/license/kusabi/stream.svg)\n[![Release Badge](https://img.shields.io/github/release/kusabi/stream.svg)](https://img.shields.io/github/release/kusabi/stream.svg)\n[![Tag Badge](https://img.shields.io/github/tag/kusabi/stream.svg)](https://img.shields.io/github/tag/kusabi/stream.svg)\n[![Issues Badge](https://img.shields.io/github/issues/kusabi/stream.svg)](https://img.shields.io/github/issues/kusabi/stream.svg)\n[![Code Size](https://img.shields.io/github/languages/code-size/kusabi/stream.svg?label=size)](https://img.shields.io/github/languages/code-size/kusabi/stream.svg)\n\n\u003csup\u003eAn implementation of a [PSR-7](https://www.php-fig.org/psr/psr-7/) \u0026 [PSR-17](https://www.php-fig.org/psr/psr-17/) conforming Stream library\u003c/sup\u003e\n\n## Installation\n\nInstallation is simple using composer.\n\n```bash\ncomposer require kusabi/stream\n```\n\nOr simply add it to your `composer.json` file\n\n```json\n{\n    \"require\": {\n        \"kusabi/stream\": \"^1.0\"\n    }\n}\n```\n\n## Using streams\n\nThe Stream class is a very basic wrapper around a stream resource.\n\n\n```php\nuse Kusabi\\Stream\\Stream;\n\n// Instantiate a Uri instance\n$stream = new Stream(fopen('php://stdin', 'r'));\n\n// Fetch the properties of the Stream\n$stream-\u003egetContents(); // Get everything from the current pointer to the end of the stream\n$stream-\u003egetSize(); // Get the size of the stream in bytes\n$stream-\u003eisSeekable();\n$stream-\u003eisReadable();\n$stream-\u003eisWritable();\n$stream-\u003eseek($offset, $whence = SEEK_SET); // Move the pointer around in the stream\n$stream-\u003etell(); // Where is the pointer in the stream\n$stream-\u003erewind(); // Set the pointer to the beginning of the stream\n$stream-\u003eread($length); // Read the next $length character from the stream\n$stream-\u003ewrite($string); // Write data into the stream. Returns the number of bytes written\n$stream-\u003egetMetadata($key = null); // Get all the metadata, or a particular key\n$stream-\u003egetStat($key = null); // Get all the fstat entries, or a particular key\n$stream-\u003eisLocal(); // Determine if the stream url is local using `stream_is_local()`\n$stream-\u003egetLine($length = null, $ending = \"\\n\"); // Fetch a line up to a length or delimiter (which ever comes first)\n$stream-\u003epipe(Stream $stream); // Copy the contents of one stream into another\n(string) $stream; // Rewind and get all the contents from the stream\n\n```\n\n\n## Using the stream factory\n\nThe Stream factory can be used to create the Stream instance too.\n\n\n```php\nuse Kusabi\\Stream\\StreamFactory;\n\n// Instantiate a Uri instance\n$factory = new StreamFactory();\n$stream = $factory-\u003ecreateStream('temp resource with data in it');\n$stream = $factory-\u003ecreateStreamFromFile('file.txt');\n$stream = $factory-\u003ecreateStreamFromResource(fopen('php://stdin', 'r'));\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkusabi%2Fstream","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkusabi%2Fstream","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkusabi%2Fstream/lists"}