code: def write_string(self, s, codec):
          
          for i in range(0, len(s), self.bufsize):
              chunk = s[i:i + self.bufsize]
              buf, consumed = codec.encode(chunk)
              assert consumed == len(chunk)
              self.write(buf)
docs: Write string encoding it with codec into stream