fhin_ = $fhin; if ($chunk_size) { $this->chunk_size_ = $chunk_size; } } /// /// @brief /// 最大 $chunk_size バイト読み込み /// /// @return /// 0 < 読み込んだバイト数 /// 0 EOF に達したが、バッファにデータが残っている。 /// -1 EOF に達した。バッファが空になった。 /// function chunkread() { $thisread = fread($this->fhin_, $this->chunk_size_); $len = strlen($thisread); if ($thisread === FALSE or $len == 0) { return 0 < $this->len() ? 0 : -1; } $this->append($thisread); //printf("%s: %d bytes in buffer\n", __METHOD__, $this->len_); return $len; } /// /// @brief /// $str を検索する。 /// /// @return /// FALSE EOF /// function read_until($str, &$found) { $len = strlen($str); $found = FALSE; $rtn = ''; while (($pos = $this->strpos($str)) === FALSE) { if ($len < $this->len()) { $rtn .= $this->get($this->len() - $len); } switch ($this->chunkread()) { case -1: // buffer empty if ($rtn === '') { return FALSE; } else { return $rtn; } case 0: // EOF $pos = $this->strpos($str); if ($pos === FALSE) { return $rtn . $this->get(); } else { $found = TRUE; $rtn .= $this->get($pos); $this->get($len); return $rtn; } } } // found $str $found = TRUE; $rtn .= $this->get($pos); $this->get($len); return $rtn; } function getline($delim = "\n") { return $this->read_until($delim, $found); } /// /// @brief /// $str を検索する。 /// /// @return /// FALSE EOF /// function write_until($fhw, $str, &$found) { $len = strlen($str); $found = FALSE; $wrote = 0; while (($pos = $this->strpos($str)) === FALSE) { if ($len < $this->len()) { $wrote += fwrite($fhw, $this->get($this->len() - $len)); } switch ($this->chunkread()) { case -1: // buffer empty return 0 < $wrote; case 0: // EOF $pos = $this->strpos($str); if ($pos === FALSE) { $wrote += fwrite($fhw, $this->get()); return 0 < $wrote; } else { $found = TRUE; $wrote += fwrite($fhw, $this->get($pos)); $this->get($len); return 0 < $wrote; } } } // found $str $found = TRUE; $wrote += fwrite($fhw, $this->get($pos)); $this->get($len); return 0 < $wrote; } } // End of file