示例#1
0
<?php

uv_fs_open(uv_default_loop(), "./tmp", UV::O_WRONLY, UV::S_IRWXU | UV::S_IRUSR, function ($r) {
    var_dump($r);
    uv_fs_ftruncate(uv_default_loop(), $r, 0, function () use($r) {
        uv_fs_close(uv_default_loop(), $r, function () {
        });
    });
});
uv_run();
示例#2
0
 private function onOpenHandle($fh, array $openArr)
 {
     list($mode) = $openArr;
     if ($mode[0] === "w") {
         \uv_fs_ftruncate($this->loop, $fh, $length = 0, function ($fh) use($openArr) {
             $this->reactor->delRef();
             if ($fh) {
                 $this->finalizeHandle($fh, $size = 0, $openArr);
             } else {
                 list(, $path, $promisor) = $openArr;
                 $promisor->fail(new FilesystemException("Failed truncating file {$path}"));
             }
         });
     } else {
         \uv_fs_fstat($this->loop, $fh, function ($fh, $stat) use($openArr) {
             $this->reactor->delRef();
             if ($fh) {
                 StatCache::set($openArr[1], $stat);
                 $this->finalizeHandle($fh, $stat["size"], $openArr);
             } else {
                 list(, $path, $promisor) = $openArr;
                 $promisor->fail(new FilesystemException("Failed reading file size from open handle pointing to {$path}"));
             }
         });
     }
 }
 /**
  * @todo
  * @param resource $fd
  * @param int $length
  * @param callable $callback
  * @return $this
  */
 public function ftruncate($fd, $length, callable $callback = null)
 {
     $self = $this;
     \uv_fs_ftruncate($this->getLoop()->getBackend(), $fd, $length, function ($fd) use($callback, $self) {
         $callback($self, $fd);
     });
     return $this;
 }