private function beforeClose()
    {
        if ($this->isWritable() && $this->remainder !== '') {
            $this->stream->write(base64_encode($this->remainder));
            $this->remainder = '';
        }
    }