open($filename); } } public function __destruct() { $this->close(); } public function open($filename) { $this->close(); $this->fileHandle = fopen($filename, 'wb'); } public function write($data) { $this->offset += strlen($data); if ($this->fileHandle === false) { throw new \Exception('No file opened.'); } else { return fwrite($this->fileHandle, $data); } } public function offset() { return $this->offset; } public function close() { if ($this->fileHandle !== false) { fclose($this->fileHandle); } $this->fileHandle = false; } } }