├── LICENSE ├── README.md ├── composer.json ├── phpdoc.dist.xml └── src ├── Concurrent ├── ConcurrentDriver.php ├── ConcurrentFile.php └── Internal │ ├── File.php │ └── FileTask.php ├── Driver.php ├── Eio ├── EioDriver.php ├── EioFile.php └── Internal │ └── EioPoll.php ├── Exception ├── Error.php ├── Exception.php ├── FileException.php └── Throwable.php ├── File.php └── functions.php /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Aaron Piotrowski 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Asynchronous File Access for Icicle 2 | 3 | Asynchronous filesystem access that is *always* non-blocking, no extensions required. 4 | 5 | This library is a component for [Icicle](https://github.com/icicleio/icicle), providing asynchronous filesystem functions and abstracting files as asynchronous [streams](https://github.com/icicleio/stream). Like other Icicle components, this library uses [Coroutines](//github.com/icicleio/icicle/wiki/Coroutines) built from [Awaitables](https://github.com/icicleio/icicle/wiki/Awaitables) and [Generators](http://www.php.net/manual/en/language.generators.overview.php) to make writing asynchronous code more like writing synchronous code. 6 | 7 | [![Build Status](https://img.shields.io/travis/icicleio/filesystem/v1.x.svg?style=flat-square)](https://travis-ci.org/icicleio/filesystem) 8 | [![Coverage Status](https://img.shields.io/coveralls/icicleio/filesystem/v1.x.svg?style=flat-square)](https://coveralls.io/r/icicleio/filesystem) 9 | [![Semantic Version](https://img.shields.io/github/release/icicleio/filesystem.svg?style=flat-square)](http://semver.org) 10 | [![MIT License](https://img.shields.io/packagist/l/icicleio/filesystem.svg?style=flat-square)](LICENSE) 11 | [![@icicleio on Twitter](https://img.shields.io/badge/twitter-%40icicleio-5189c7.svg?style=flat-square)](https://twitter.com/icicleio) 12 | 13 | #### Documentation and Support 14 | 15 | - [Full API Documentation](https://icicle.io/docs) 16 | - [Official Twitter](https://twitter.com/icicleio) 17 | - [Gitter Chat](https://gitter.im/icicleio/icicle) 18 | 19 | ##### Requirements 20 | 21 | - PHP 5.5+ for v0.1.x branch (current stable) and v1.x branch (mirrors current stable) 22 | - PHP 7 for v2.0 branch (under development) supporting generator delegation and return expressions 23 | 24 | ##### Installation 25 | 26 | The recommended way to install is with the [Composer](http://getcomposer.org/) package manager. (See the [Composer installation guide](https://getcomposer.org/doc/00-intro.md) for information on installing and using Composer.) 27 | 28 | Run the following command to use this library in your project: 29 | 30 | ```bash 31 | composer require icicleio/filesystem 32 | ``` 33 | 34 | You can also manually edit `composer.json` to add this library as a project requirement. 35 | 36 | ```js 37 | // composer.json 38 | { 39 | "require": { 40 | "icicleio/filesystem": "^0.1" 41 | } 42 | } 43 | ``` 44 | 45 | ##### Suggested 46 | 47 | - [eio extension](http://php.net/manual/en/book.eio.php): Uses libeio to provide asynchronous file access (v1.2.6+ required). 48 | 49 | #### Example 50 | 51 | ```php 52 | #!/usr/bin/env php 53 | write('testing')); 70 | 71 | printf("Wrote %d bytes to file.\n", $written); 72 | 73 | // Seek to beginning of file. 74 | yield $file->seek(0); 75 | 76 | // Read data from file. 77 | $data = (yield $file->read()); 78 | } finally { 79 | $file->close(); 80 | } 81 | 82 | printf("Read data from file: %s\n", $data); 83 | 84 | // Remove file. 85 | yield File\unlink($path); 86 | })->done(); 87 | 88 | Loop\run(); 89 | ``` -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "icicleio/filesystem", 3 | "description": "Asynchronous filesystem component for Icicle.", 4 | "keywords": [ 5 | "asynchronous", 6 | "async", 7 | "file", 8 | "filesystem" 9 | ], 10 | "homepage": "http://icicle.io", 11 | "license": "MIT", 12 | "authors": [ 13 | { 14 | "name": "Aaron Piotrowski", 15 | "email": "aaron@icicle.io" 16 | } 17 | ], 18 | "require": { 19 | "icicleio/icicle": "^2.0", 20 | "icicleio/stream": "^2.0", 21 | "icicleio/concurrent": "^2.0" 22 | }, 23 | "require-dev": { 24 | "phpunit/phpunit": "^5.0" 25 | }, 26 | "minimum-stability": "dev", 27 | "suggest": { 28 | "ext-eio": "Extension providing better performance for asynchronous file access. v1.2.6+ required." 29 | }, 30 | "extra": { 31 | "branch-alias": { 32 | "dev-master": "2.0.x-dev" 33 | } 34 | }, 35 | "autoload": { 36 | "psr-4": { 37 | "Icicle\\File\\": "src" 38 | }, 39 | "files": [ 40 | "src/functions.php" 41 | ] 42 | }, 43 | "autoload-dev": { 44 | "psr-4": { 45 | "Icicle\\Tests\\File\\": "tests" 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /phpdoc.dist.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Icicle 4 | 5 | build/docs 6 | utf8 7 | 8 | 9 | build/docs 10 | 11 | 12 | warn 13 | 14 | build/log/docs/{DATE}.log 15 | 16 | 17 | 18 |