1
0
mirror of https://github.com/danog/file.git synced 2024-11-26 20:04:51 +01:00
file/lib/Handle.php

77 lines
1.8 KiB
PHP
Raw Normal View History

<?php
2015-08-13 01:02:41 +02:00
namespace Amp\File;
2017-01-11 14:22:06 +01:00
use AsyncInterop\Promise;
2015-08-13 01:02:41 +02:00
interface Handle {
/**
* Read $len bytes from the open file handle starting at $offset
*
* @param int $length
2017-01-11 14:22:06 +01:00
* @return \AsyncInterop\Promise<string>
2015-08-13 01:02:41 +02:00
*/
2016-11-15 06:17:19 +01:00
public function read(int $length): Promise;
2015-08-13 01:02:41 +02:00
/**
* Write $data to the open file handle starting at $offset
*
* @param string $data
2017-01-11 14:22:06 +01:00
* @return \AsyncInterop\Promise<int>
2015-08-13 01:02:41 +02:00
*/
2016-11-15 06:17:19 +01:00
public function write(string $data): Promise;
2015-08-13 01:02:41 +02:00
/**
* Close the file handle
*
* Applications are not required to manually close handles -- they will
* be unloaded automatically when the object is garbage collected.
*
2017-01-11 14:22:06 +01:00
* @return \AsyncInterop\Promise
2015-08-13 01:02:41 +02:00
*/
2016-11-15 06:17:19 +01:00
public function close(): Promise;
2015-08-13 01:02:41 +02:00
/**
* Set the handle's internal pointer position
*
* $whence values:
*
* SEEK_SET - Set position equal to offset bytes.
* SEEK_CUR - Set position to current location plus offset.
* SEEK_END - Set position to end-of-file plus offset.
*
* @param int $position
* @param int $whence
2017-01-11 14:22:06 +01:00
* @return \AsyncInterop\Promise<int> New offset position.
2015-08-13 01:02:41 +02:00
*/
2016-11-15 06:17:19 +01:00
public function seek(int $position, int $whence = \SEEK_SET): Promise;
2015-08-13 01:02:41 +02:00
/**
* Return the current internal offset position of the file handle
*
* @return int
*/
public function tell(): int;
2015-08-13 01:02:41 +02:00
/**
* Test for "end-of-file" on the file handle
*
* @return bool
*/
public function eof(): bool;
2015-08-13 01:02:41 +02:00
/**
* Retrieve the path used when opening the file handle
*
* @return string
*/
public function path(): string;
2015-08-13 01:02:41 +02:00
/**
* Retrieve the mode used when opening the file handle
*
* @return string
*/
public function mode(): string;
2015-08-13 01:02:41 +02:00
}