2016-12-30 03:59:59 +01:00
|
|
|
<?php
|
2015-08-13 01:02:41 +02:00
|
|
|
|
|
|
|
namespace Amp\File;
|
|
|
|
|
2017-05-12 22:43:23 +02:00
|
|
|
use Amp\ByteStream\InputStream;
|
|
|
|
use Amp\ByteStream\OutputStream;
|
2017-03-17 04:39:49 +01:00
|
|
|
use Amp\Promise;
|
2016-08-24 06:55:06 +02:00
|
|
|
|
2018-10-27 17:57:31 +02:00
|
|
|
interface Handle extends InputStream, OutputStream
|
|
|
|
{
|
2017-05-12 22:43:23 +02:00
|
|
|
const DEFAULT_READ_LENGTH = 8192;
|
|
|
|
|
2015-08-13 01:02:41 +02:00
|
|
|
/**
|
2017-06-17 23:41:57 +02:00
|
|
|
* Read $len bytes from the open file handle starting at $offset.
|
2015-08-13 01:02:41 +02:00
|
|
|
*
|
2016-08-24 06:55:06 +02:00
|
|
|
* @param int $length
|
2017-05-12 22:43:23 +02:00
|
|
|
* @return \Amp\Promise<string|null>
|
2015-08-13 01:02:41 +02:00
|
|
|
*/
|
2017-06-17 01:22:57 +02:00
|
|
|
public function read(int $length = self::DEFAULT_READ_LENGTH): Promise;
|
2015-08-13 01:02:41 +02:00
|
|
|
|
|
|
|
/**
|
2017-06-17 23:41:57 +02:00
|
|
|
* Write $data to the open file handle starting at $offset.
|
2015-08-13 01:02:41 +02:00
|
|
|
*
|
|
|
|
* @param string $data
|
2017-03-17 04:39:49 +01:00
|
|
|
* @return \Amp\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
|
|
|
|
2017-05-12 22:43:23 +02:00
|
|
|
/**
|
|
|
|
* Write $data to the open file handle and close the handle once the write completes.
|
|
|
|
*
|
|
|
|
* @param string $data
|
|
|
|
*
|
|
|
|
* @return \Amp\Promise<int>
|
|
|
|
*/
|
|
|
|
public function end(string $data = ""): Promise;
|
|
|
|
|
2015-08-13 01:02:41 +02:00
|
|
|
/**
|
2017-06-17 23:41:57 +02:00
|
|
|
* Close the file handle.
|
2015-08-13 01:02:41 +02:00
|
|
|
*
|
|
|
|
* Applications are not required to manually close handles -- they will
|
|
|
|
* be unloaded automatically when the object is garbage collected.
|
|
|
|
*
|
2017-03-17 04:39:49 +01:00
|
|
|
* @return \Amp\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
|
|
|
|
|
|
|
/**
|
2018-10-29 05:55:11 +01:00
|
|
|
* Truncates the file to the given length. If $size is larger than the current file size, the file is extended
|
|
|
|
* with null bytes.
|
|
|
|
*
|
|
|
|
* @param int $size New file size.
|
|
|
|
*
|
|
|
|
* @return \Amp\Promise
|
|
|
|
*/
|
|
|
|
public function truncate(int $size): Promise;
|
|
|
|
|
|
|
|
/**
|
2017-06-17 23:41:57 +02:00
|
|
|
* Set the handle's internal pointer position.
|
2015-08-13 01:02:41 +02:00
|
|
|
*
|
|
|
|
* $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-03-17 04:39:49 +01:00
|
|
|
* @return \Amp\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
|
|
|
|
|
|
|
/**
|
2017-06-17 23:41:57 +02:00
|
|
|
* Return the current internal offset position of the file handle.
|
2015-08-13 01:02:41 +02:00
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
2016-08-24 06:55:06 +02:00
|
|
|
public function tell(): int;
|
2015-08-13 01:02:41 +02:00
|
|
|
|
|
|
|
/**
|
2017-06-17 23:41:57 +02:00
|
|
|
* Test for "end-of-file" on the file handle.
|
2015-08-13 01:02:41 +02:00
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
2016-08-24 06:55:06 +02:00
|
|
|
public function eof(): bool;
|
2015-08-13 01:02:41 +02:00
|
|
|
|
|
|
|
/**
|
2017-06-17 23:41:57 +02:00
|
|
|
* Retrieve the path used when opening the file handle.
|
2015-08-13 01:02:41 +02:00
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2016-08-24 06:55:06 +02:00
|
|
|
public function path(): string;
|
2015-08-13 01:02:41 +02:00
|
|
|
|
|
|
|
/**
|
2017-06-17 23:41:57 +02:00
|
|
|
* Retrieve the mode used when opening the file handle.
|
2015-08-13 01:02:41 +02:00
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2016-08-24 06:55:06 +02:00
|
|
|
public function mode(): string;
|
2015-08-13 01:02:41 +02:00
|
|
|
}
|