def METHOD_NAME(self, dir=None):
    """
    writes file to dir/filename if dir isn't specified the current
    working dir is used. Additionally it tries to set the owner/group
    and permissions.
    """
    if not dir:
        dir = os.getcwdb()
    fn = os.path.join(dir, self.name)
    with open(fn, 'wb') as f:
        f.write(self.getvalue())
    os.chmod(fn, self.mode)
    uid = self.uid
    if uid != os.geteuid() or os.geteuid() != 0:
        uid = -1
    gid = self.gid
    if gid not in os.getgroups() or os.getegid() != 0:
        gid = -1
    os.chown(fn, uid, gid)