From 07f5140771388c9e0c8a99b0dd2e5d950bdb173b Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Thu, 14 Oct 2021 15:16:42 +1100 Subject: moving h-source subdir out. --- .../classes/Swift/ByteStream/FileByteStream.php | 177 +++++++++++++++++++++ 1 file changed, 177 insertions(+) create mode 100755 External/swiftmailer/lib/classes/Swift/ByteStream/FileByteStream.php (limited to 'External/swiftmailer/lib/classes/Swift/ByteStream/FileByteStream.php') diff --git a/External/swiftmailer/lib/classes/Swift/ByteStream/FileByteStream.php b/External/swiftmailer/lib/classes/Swift/ByteStream/FileByteStream.php new file mode 100755 index 0000000..14773c2 --- /dev/null +++ b/External/swiftmailer/lib/classes/Swift/ByteStream/FileByteStream.php @@ -0,0 +1,177 @@ +_path = $path; + $this->_mode = $writable ? 'w+b' : 'rb'; + $this->_quotes = get_magic_quotes_runtime(); + } + + /** + * Get the complete path to the file. + * @return string + */ + public function getPath() + { + return $this->_path; + } + + /** + * Reads $length bytes from the stream into a string and moves the pointer + * through the stream by $length. If less bytes exist than are requested the + * remaining bytes are given instead. If no bytes are remaining at all, boolean + * false is returned. + * @param int $length + * @return string + * @throws Swift_IoException + */ + public function read($length) + { + $fp = $this->_getReadHandle(); + if (!feof($fp)) + { + if ($this->_quotes) + { + set_magic_quotes_runtime(0); + } + $bytes = fread($fp, $length); + if ($this->_quotes) + { + set_magic_quotes_runtime(1); + } + $this->_offset = ftell($fp); + return $bytes; + } + else + { + return false; + } + } + + /** + * Move the internal read pointer to $byteOffset in the stream. + * @param int $byteOffset + * @return boolean + */ + public function setReadPointer($byteOffset) + { + if (isset($this->_reader)) + { + fseek($this->_reader, $byteOffset, SEEK_SET); + } + $this->_offset = $byteOffset; + } + + // -- Private methods + + /** Just write the bytes to the file */ + protected function _commit($bytes) + { + fwrite($this->_getWriteHandle(), $bytes); + $this->_resetReadHandle(); + } + + /** Not used */ + protected function _flush() + { + } + + /** Get the resource for reading */ + private function _getReadHandle() + { + if (!isset($this->_reader)) + { + if (!$this->_reader = fopen($this->_path, 'rb')) + { + throw new Swift_IoException( + 'Unable to open file for reading [' . $this->_path . ']' + ); + } + fseek($this->_reader, $this->_offset, SEEK_SET); + } + return $this->_reader; + } + + /** Get the resource for writing */ + private function _getWriteHandle() + { + if (!isset($this->_writer)) + { + if (!$this->_writer = fopen($this->_path, $this->_mode)) + { + throw new Swift_IoException( + 'Unable to open file for writing [' . $this->_path . ']' + ); + } + } + return $this->_writer; + } + + /** Force a reload of the resource for writing */ + private function _resetWriteHandle() + { + if (isset($this->_writer)) + { + fclose($this->_writer); + $this->_writer = null; + } + } + + /** Force a reload of the resource for reading */ + private function _resetReadHandle() + { + if (isset($this->_reader)) + { + fclose($this->_reader); + $this->_reader = null; + } + } + +} -- cgit v1.2.3