{"id":36995559,"url":"https://github.com/tarsana/filesystem","last_synced_at":"2026-01-13T23:47:53.108Z","repository":{"id":57065316,"uuid":"48081403","full_name":"tarsana/filesystem","owner":"tarsana","description":"Simple classes to handle filesystem operations.","archived":false,"fork":false,"pushed_at":"2018-02-11T16:13:49.000Z","size":192,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-10-06T15:41:40.662Z","etag":null,"topics":["filesystem","input","mocking","output","php","reader","resource","writer"],"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/tarsana.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}},"created_at":"2015-12-16T02:12:47.000Z","updated_at":"2023-02-03T06:54:07.000Z","dependencies_parsed_at":"2022-08-24T14:53:57.749Z","dependency_job_id":null,"html_url":"https://github.com/tarsana/filesystem","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/tarsana/filesystem","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tarsana%2Ffilesystem","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tarsana%2Ffilesystem/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tarsana%2Ffilesystem/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tarsana%2Ffilesystem/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tarsana","download_url":"https://codeload.github.com/tarsana/filesystem/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tarsana%2Ffilesystem/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28405359,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-13T21:51:37.118Z","status":"ssl_error","status_checked_at":"2026-01-13T21:45:14.585Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["filesystem","input","mocking","output","php","reader","resource","writer"],"created_at":"2026-01-13T23:47:53.035Z","updated_at":"2026-01-13T23:47:53.089Z","avatar_url":"https://github.com/tarsana.png","language":"PHP","funding_links":["https://paypal.me/webneat"],"categories":[],"sub_categories":[],"readme":"# Tarsana Filesystem Package\n\n[![Build Status](https://travis-ci.org/tarsana/filesystem.svg?branch=master)](https://travis-ci.org/tarsana/filesystem)\n[![Coverage Status](https://coveralls.io/repos/github/tarsana/filesystem/badge.svg?branch=master)](https://coveralls.io/github/tarsana/filesystem?branch=master)\n[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://paypal.me/webneat)\n[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat)](https://github.com/tarsana/filesystem/blob/master/LICENSE)\n\nSimple classes to handle Filesystem operations.\n\n## Installation\n\nInstall it using composer\n\n```\ncomposer require tarsana/filesystem\n```\n\n## Handeling Files and Directories\n\nThe `Filesystem` class was designed to be used easily and support call chaining which makes the code more readable.\n\n```php\n// Create a Filesystem instance given a root path\n$fs = new Tarsana\\Filesystem('path/to/fs/root/directory');\n```\n\n### Checking Paths\n\nMaybe you need to check if a specific path is a file\n\n```php\nif ($fs-\u003eisFile('path'))\n```\n\nor a directory\n\n```php\nif ($fs-\u003eisDir('path'))\n```\n\nor you just want to know it exists, no matter it's a file or directory\n\n```php\nif ($fs-\u003eisAny('path'))\n```\n\nWhat if you need to check multiple paths at once ?\n\n```php\nif ($fs-\u003eareFiles(['path1', 'path2', 'path3']))\nif ($fs-\u003eareDirs(['path1', 'path2', 'path3']))\nif ($fs-\u003eareAny(['path1', 'path2', 'path3']))\n```\n\nBut what if you want to know the type of a path without having to do multiple checks ?\n\n```php\n$fs-\u003ewhatIs('path-pattern')\n```\n\nYou can use wildcard pattern as argument to this function and the result will be:\n\n- `'file'`: if a single file corresponds to the pattern.\n\n- `'dir'`: if a single directory corresponds to the pattern.\n\n- `'collection'`: if multiple files and/or directories correspond to the pattern.\n\n- `'nothing'`: if nothing corresponds to the pattern.\n\n### Finding Files and Directories\n\nNow what if you want to get all files and directories corresponding to a pattern ?\n\n```php\n$collection = $fs-\u003efind('pattern'); // a Collection instance\n\nforeach ($collection-\u003easArray() as $fileOrDir) {\n\t// Handle the file or directory\n}\n```\n\nYou can also manipulate the collection\n\n```php\n$collection-\u003ecount(); // number of elements\n$collection-\u003eadd($fs-\u003efile('path/to/file')); // add new element to the collection\n$collection-\u003econtains('path'); // checks if the collection contains an element with that path\n$collection-\u003eremove('path'); // remove the element having the path from the collection\n\n$collection-\u003efiles(); // a new collection containing only files\n$collection-\u003edirs(); // a new collection containing only directories\n\n$collection-\u003efirst(); // the first element\n$collection-\u003elast(); // the last element\n\n$collection-\u003epaths(); // array of paths of the files and directories\n$collection-\u003enames(); // array of names of the files and directories\n```\n\n### Handling Files\n\nWell, to handle a file, you should get it first\n\n```php\n$file = $fs-\u003efile('path/to/file');\n```\n\nNotice that this will throw an exception if the file is not found. If you want to create it when missing; specify `true` in the second argument\n\n```php\n$file = $fs-\u003efile('path/to/file', true);\n```\n\nYou can also get or create multiple files at once\n\n```php\n$files = $fs-\u003efiles([\n\t'path/to/file1',\n\t'path/to/file2',\n\t'path/to/file3'\n]); // specify the second argument as true if you want missing files to be created\n\nforeach ($files-\u003easArray() as $file) {\n\t// Handle the file\n}\n```\n\nNow that you have the file, you can play with it\n\n```php\n$file-\u003ename(); // get the name\n$file-\u003ename('new-name.txt'); // renaming the file\n\n$file-\u003epath(); // get the absolute path\n$file-\u003epath('new/absolute/path'); // moving the file\n\n$file-\u003econtent(); // reading the content\n$file-\u003econtent('new content'); // writing to the file\n$file-\u003eappend('additional content'); // add content to the file\n\n$file-\u003ehash(); // get the md5 hash of the content\n$file-\u003eextension(); // get the extension (like \"txt\" or \"php\")\n\n$file-\u003eperms(); // get the file permissions as string (like \"0755\")\n$file-\u003eisWritable(); // check if the file is writable\n$file-\u003eisExecutable(); // check if the file is executable\n\n$copy = $file-\u003ecopyAs('absolute/path/to/file-copy'); // Copy the file\n$file-\u003eremove(); // Remove the file\n```\n\nNotice that all setters return the same instance to enable call chaining.\n\n### Handling Directories\n\nJust like the file, you can get a directory like that\n\n```php\n$dir = $fs-\u003edir('path/to/dir'); // throws exception if the directory not found\n$dir = $fs-\u003edir('path/to/dir', true); // creates the directory if not found\n$dirs = $fs-\u003edirs([\n\t'path/to/file1',\n\t'path/to/file2',\n\t'path/to/file3'\n]); // a collection containing directories\n```\n\nHaving a directory, you can play with it\n```php\n$dir-\u003ename(); // get the name\n$dir-\u003ename('new-name'); // renaming the directory\n\n$dir-\u003epath(); // get the absolute path\n$dir-\u003epath('new/absolute/path'); // moving the directory\n\n$dir-\u003eperms(); // get the directory permissions as string (like \"0755\")\n\n$copy = $dir-\u003ecopyAs('absolute/path/to/dir-copy'); // Copy the directory\n$dir-\u003eremove(); // Remove the directory\n\n$dir-\u003efs(); // get a Filesystem instance having this directory as root\n```\n\nNotice that all setters return the same instance to enable call chaining.\n\n## Reading \u0026 Writing to Resources\n\n### Writer\n\n`Tarsana\\Filesystem\\Resource\\Writer` gives the possibility to write content to any resource.\n\n```php\n// Default constructor uses STDOUT by default\n$stdout = new Writer;\n// Any writable resource can be used\n$res = fopen('temp.txt', 'w');\n$out = Writer($res);\n// Or just give the path\n$out = Writer('php://memory');\n\n// Writing content\n$out-\u003ewrite('Hello ')-\u003ewrite('World !');\n// Writes \"Hello World !\" to the resource\n$out-\u003ewriteLine('Hi');\n// Writes \"Hi\".PHP_EOL to the resource\n\n// The resource is closed when the $out object is destructed\n// But you can still close it before\n$out-\u003eclose();\n```\n\n### Reader\n\n`Tarsana\\Filesystem\\Resources\\Reader` gives the possibility to read content from any resource. Constructors are the same as `Writer` but the default resource is `STDIN`.\n\n```php\n$stdin = new Reader; // when no parameter is given, it uses STDIN by default\n\n$stdin-\u003eread(); // reads the whole content of STDIN\n$stdin-\u003eread(100); // reads 100 bytes from STDIN\n$stdin-\u003ereadUntil(' '); // reads until the first ' ' (space) or EOF\n$stdin-\u003ereadLine(); // reads until PHP_EOL or EOF\n// If the STDIN is empty and we do\n$stdin-\u003eblocking(false)-\u003eread();\n// This will return immediately an empty string; no blocking !\n```\n\n### Buffer\n\n`Tarsana\\Filesystem\\Resource\\Buffer` is a Reader and Writer at the same time. If no resource is given, it uses `php://memory` to store content.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftarsana%2Ffilesystem","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftarsana%2Ffilesystem","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftarsana%2Ffilesystem/lists"}