code: def tar_add_bytes(tf, filename, bytestring):
      
      if not isinstance(bytestring, bytes):  # it hasn't been encoded yet
          bytestring = bytestring.encode('ascii')
      buff = io.BytesIO(bytestring)
      tarinfo = tarfile.TarInfo(filename)
      tarinfo.size = len(bytestring)
      tf.addfile(tarinfo, buff)
docs: Add a file to a tar archive
  
      Args:
          tf (tarfile.TarFile): tarfile to add the file to
          filename (str): path within the tar file
          bytestring (bytes or str): file contents. Must be :class:`bytes` or
              ascii-encodable :class:`str`