Reads whole file
@param  callable $cb Callback
@param  integer $pri Priority
@return boolean       Success
329936
public function readAll($cb, $pri = EIO_PRI_DEFAULT)
    {
        $cb = CallbackWrapper::forceWrap($cb);
        if (!$this->fd) {
            if ($cb) {
                $cb($this, false);
            }
            return false;
        }
        $this->statRefresh(
            function ($file, $stat) use ($cb, $pri) {
                if (!$stat) {
                    if ($cb) {
                        $cb($file, false);
                    }
                    return;
                }

                $offset = 0;
                $buf = '';
                $size = $stat['size'];

                eio_read(
                    $file->fd,
                    min($file->chunkSize, $size),
                    0,
                    $pri,
                    $this->readAllGenHandler($cb, $size, $offset, $pri, $buf),
                    $file
                );
            },
            $pri
        );

        return true;
    }
777284
public static function open($path, $flags, $cb, $mode = null, $pri = EIO_PRI_DEFAULT)
    {
        $cb = CallbackWrapper::forceWrap($cb);
        if (!FileSystem::$supported) {
            $mode = File::convertFlags($flags, true);
            $fd = fopen($path, $mode);
            if (!$fd) {
                $cb(false);
                return false;
            }
            $file = new File($fd, $path);
            $cb($file);
            return true;
        }
        $fdCacheKey = $path . "\x00" . $flags;
        $noncache = mb_orig_strpos($flags, '!') !== false;
        $flags = File::convertFlags($flags);
        if (!$noncache && ($item = FileSystem::$fdCache->get($fdCacheKey))) { // cache hit
            $file = $item->getValue();
            if ($file === null) { // operation in progress
                $item->addListener($cb);
            } else { // hit
                $cb($file);
            }
            return null;
        } elseif (!$noncache) {
            $item = FileSystem::$fdCache->put($fdCacheKey, null);
            $item->addListener($cb);
        }
        return eio_open($path, $flags, $mode, $pri, function ($path, $fd) use ($cb, $flags, $fdCacheKey, $noncache) {
            if ($fd === -1) {
                if ($noncache) {
                    $cb(false);
                } else {
                    FileSystem::$fdCache->put($fdCacheKey, false, self::$badFDttl);
                }
                return;
            }
            $file = new File($fd, $path);
            $file->append = ($flags | EIO_O_APPEND) === $flags;
            if ($file->append) {
                $file->stat(function ($file, $stat) use ($cb, $noncache, $fdCacheKey) {
                    $file->offset = $stat['size'];
                    if (!$noncache) {
                        $file->fdCacheKey = $fdCacheKey;
                        FileSystem::$fdCache->put($fdCacheKey, $file);
                    } else {
                        $cb($file);
                    }
                });
            } else {
                if (!$noncache) {
                    $file->fdCacheKey = $fdCacheKey;
                    FileSystem::$fdCache->put($fdCacheKey, $file);
                } else {
                    $cb($file);
                }
            }
        }, $path);
    }
837717
public static function stat($path, $cb, $pri = EIO_PRI_DEFAULT)
    {
        $cb = CallbackWrapper::forceWrap($cb);
        if (!self::$supported) {
            $cb($path, FileSystem::statPrepare(@stat($path)));
            return true;
        }
        return eio_stat($path, $pri, function ($path, $stat) use ($cb) {
            $cb($path, FileSystem::statPrepare($stat));
        }, $path);
    }
135578
protected function readAllChunkedGenHandler($cb, $chunkcb, $size, &$offset, $pri)
    {
        return function ($file, $data) use ($cb, $chunkcb, $size, &$offset, $pri) {
            $chunkcb($file, $data);
            $offset += mb_orig_strlen($data);
            $len = min($file->chunkSize, $size - $offset);

            if ($offset >= $size) {
                $cb($file, true);
                return;
            }

            eio_read(
                $file->fd,
                $len,
                $offset,
                $pri,
                $this->readAllChunkedGenHandler($cb, $chunkcb, $size, $offset, $pri),
                $file
            );
        };
    }
1374186
public function rmWatch($path, $cb)
    {
        $path = realpath($path);

        if (!isset($this->files[$path])) {
            return false;
        }
        if (($k = array_search($cb, $this->files[$path], true)) !== false) {
            unset($this->files[$path][$k]);
        }
        if (sizeof($this->files[$path]) === 0) {
            if ($this->inotify) {
                if (($descriptor = array_search($path, $this->descriptors)) !== false) {
                    inotify_rm_watch($this->inotify, $cb);
                }
            }
            unset($this->files[$path]);
        }
        return true;
    }
89035
public static function sync($cb = null, $pri = EIO_PRI_DEFAULT)
    {
        $cb = CallbackWrapper::forceWrap($cb);
        if (!self::$supported) {
            if ($cb) {
                $cb(false);
            }
            return false;
        }
        return eio_sync($pri, $cb);
    }
1159708
public function read($count_bytes) {
    // If we have data in the read_buffer then use it.
    $readBuffer_size = strlen($this->read_buffer);
    $bytes_available = $readBuffer_size - $this->buffer_read_position;

    // If there are no more bytes available then get some.
    if ($bytes_available === 0 && !$this->eof) {
      // If we know the object size, check it first.
      $object_bytes_read = $this->object_block_start_position +
                           $this->buffer_read_position;
      if ($object_bytes_read === $this->object_total_length ||
          !isset($this->next_read_position)) {
        $this->eof = true;
        return false;
      }
      if (!$this->fillReadBuffer($this->next_read_position)) {
        return false;
      }
      // Re-calculate the number of bytes we can serve.
      $readBuffer_size = strlen($this->read_buffer);
      $bytes_available = $readBuffer_size - $this->buffer_read_position;
    }

    if ($bytes_available > 0) {
      $bytes_to_read = min($bytes_available, $count_bytes);
      $current_buffer_position = $this->buffer_read_position;
      $this->buffer_read_position += $bytes_to_read;

      return substr($this->read_buffer,
                    $current_buffer_position,
                    $bytes_to_read);
    }

    return false;
  }
1157703
public static function mkdir($path, $mode, $cb = null, $pri = EIO_PRI_DEFAULT)
    {
        $cb = CallbackWrapper::forceWrap($cb);
        if (!FileSystem::$supported) {
            $r = mkdir($path, $mode);
            if ($cb) {
                $cb($path, $r);
            }
            return $r;
        }
        return eio_mkdir($path, $mode, $pri, $cb, $path);
    }
959431
public function read($delim = '#')
    {
        $file = file_get_contents($this->file);

        $delim = preg_quote($delim);
        if (preg_match("/#\s$delim\s(.*?)\s#\s\\\\$delim/s", $file, $matches)) {
            return trim($matches[1]);
        } else {
            return false;
        }
    }
129934
public function read($key)
    {
        $this->init();
        list($containerName, $key) = $this->tokenizeKey($key);

        try {
            $blob = $this->blobProxy->getBlob($containerName, $key);

            return stream_get_contents($blob->getContentStream());
        } catch (ServiceException $e) {
            $this->failIfContainerNotFound($e, sprintf('read key "%s"', $key), $containerName);

            return false;
        }
    }
314342
public static function truncate($path, $offset = 0, $cb = null, $pri = EIO_PRI_DEFAULT)
    {
        $cb = CallbackWrapper::forceWrap($cb);
        if (!FileSystem::$supported) {
            $fp = fopen($path, 'r+');
            $r = $fp && ftruncate($fp, $offset);
            if ($cb) {
                $cb($path, $r);
            }
            return $r;
        }
        return eio_truncate($path, $offset, $pri, $cb, $path);
    }
707190
function readFile (archive, name, opts, cb) {
  if (typeof opts === 'function') {
    cb = opts
    opts = {}
  }

  return maybe(cb, async function () {
    opts = opts || {}
    if (typeof opts === 'string') {
      opts = { encoding: opts }
    }
    opts.encoding = toValidEncoding(opts.encoding)

    // check that it's a file
    const st = await stat(archive, name)
    if (!st.isFile()) {
      throw new NotAFileError()
    }

    // read the file
    return new Promise((resolve, reject) => {
      archive.readFile(name, opts, (err, data) => {
        if (err) reject(toBeakerError(err, 'readFile'))
        else resolve(data)
      })
    })
  })
}
1147962
public static function readfileChunked($path, $cb, $chunkcb, $pri = EIO_PRI_DEFAULT)
    {
        $cb = CallbackWrapper::forceWrap($cb);
        if (!FileSystem::$supported) {
            $chunkcb($path, $r = readfile($path));
            $cb($r !== false);
            return;
        }
        FileSystem::open($path, 'r!', function ($file) use ($path, $cb, $chunkcb, $pri) {
            if (!$file) {
                $cb($path, false);
                return;
            }
            $file->readAllChunked($cb, $chunkcb, $pri);
        }, null, $pri);
    }
1057353
public function readfileChunked($filename, $retbytes = false)
    {
        $chunksize = 1 * (1024 * 1024); // how many bytes per chunk
        $buffer = '';
        $cnt = 0;
        $handle = fopen($filename, 'rb');
        if ($handle === false) {
            return false;
        }
        while (!feof($handle)) {
            $buffer = fread($handle, $chunksize);
            echo $buffer;
            ob_flush();
            flush();
            if ($retbytes) {
                $cnt += $this->binaryStrLen($buffer);
            }
        }
        $status = fclose($handle);
        if ($retbytes && $status) {
            return $cnt; // return num. bytes delivered like readfile() does.
        }
        return $status;
    }
636668
public static byte[] readRawBytes(ByteBuf cb)
    {
        byte[] bytes = new byte[cb.readableBytes()];
        cb.readBytes(bytes);
        return bytes;
    }
312775
public function sync($cb, $pri = EIO_PRI_DEFAULT)
    {
        $cb = CallbackWrapper::forceWrap($cb);
        if (!$this->fd) {
            if ($cb) {
                $cb($this, false);
            }
            return false;
        }
        if (!FileSystem::$supported) {
            $cb($this, true);
            return false;
        }
        return eio_fsync($this->fd, $pri, $cb, $this);
    }
954977
public function chown($uid, $gid = -1, $cb = null, $pri = EIO_PRI_DEFAULT)
    {
        $cb = CallbackWrapper::forceWrap($cb);
        if (!$this->fd) {
            if ($cb) {
                $cb($this, false);
            }
            return false;
        }
        if (!FileSystem::$supported) {
            $r = chown($this->path, $uid);
            if ($gid !== -1) {
                $r = $r && chgrp($this->path, $gid);
            }
            if ($cb) {
                $cb($this, $r);
            }
            return false;
        }
        return eio_fchown($this->fd, $uid, $gid, $pri, $cb, $this);
    }