2016-06-23 23:51:08 +02:00
|
|
|
<?php
|
2016-07-14 15:15:50 +02:00
|
|
|
|
|
|
|
set_include_path(get_include_path().PATH_SEPARATOR.dirname(__FILE__).DIRECTORY_SEPARATOR.'libpy2php');
|
|
|
|
require_once 'libpy2php.php';
|
|
|
|
require_once 'os.php';
|
|
|
|
class file
|
|
|
|
{
|
|
|
|
public function __construct($path)
|
|
|
|
{
|
2016-06-23 23:51:08 +02:00
|
|
|
$this->_path = $path;
|
|
|
|
}
|
2016-07-14 15:15:50 +02:00
|
|
|
|
2016-06-23 23:51:08 +02:00
|
|
|
/**
|
|
|
|
* truncates the file and create new with :param bytes.
|
2016-07-14 15:15:50 +02:00
|
|
|
* :return number of bytes written.
|
2016-06-23 23:51:08 +02:00
|
|
|
*/
|
2016-07-14 15:15:50 +02:00
|
|
|
public function write_bytes($bytes)
|
|
|
|
{
|
2016-06-23 23:51:08 +02:00
|
|
|
// py2php.fixme "with" unsupported.
|
|
|
|
}
|
2016-07-14 15:15:50 +02:00
|
|
|
|
2016-06-23 23:51:08 +02:00
|
|
|
/**
|
2016-07-14 15:15:50 +02:00
|
|
|
* read the file as bytes. :return b'' on file not exist.
|
2016-06-23 23:51:08 +02:00
|
|
|
*/
|
2016-07-14 15:15:50 +02:00
|
|
|
public function read_bytes()
|
|
|
|
{
|
2016-06-23 23:51:08 +02:00
|
|
|
if (!(new exists($this->_path))) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
// py2php.fixme "with" unsupported.
|
|
|
|
}
|
2016-07-14 15:15:50 +02:00
|
|
|
|
2016-06-23 23:51:08 +02:00
|
|
|
/**
|
2016-07-14 15:15:50 +02:00
|
|
|
* tries to open with os default viewer.
|
2016-06-23 23:51:08 +02:00
|
|
|
*/
|
2016-07-14 15:15:50 +02:00
|
|
|
public function open()
|
|
|
|
{
|
|
|
|
new call((os::name == 'nt') ? 'cmd /c start "" "'.$this->_path.'"' : [platform::startswith('darwin') ? 'open' : 'xdg-open', $this->_path]);
|
2016-06-23 23:51:08 +02:00
|
|
|
}
|
2016-07-14 15:15:50 +02:00
|
|
|
|
2016-06-23 23:51:08 +02:00
|
|
|
/**
|
2016-07-14 15:15:50 +02:00
|
|
|
* try to remove the file.
|
2016-06-23 23:51:08 +02:00
|
|
|
*/
|
2016-07-14 15:15:50 +02:00
|
|
|
public function remove()
|
|
|
|
{
|
2016-06-23 23:51:08 +02:00
|
|
|
try {
|
|
|
|
os::remove($this->_path);
|
2016-07-14 15:15:50 +02:00
|
|
|
} catch (FileNotFoundError $e) {
|
2016-06-23 23:51:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|