def METHOD_NAME(cls, filename: str, env: BuildEnvironment, builder: Builder) -> None:
    def escape(string: str) -> str:
        return re.sub("\\s+", " ", string)
    with open(os.path.join(filename), 'wb') as f:
        # header
        f.write(('# Sphinx inventory version 2\n'
                 '# Project: %s\n'
                 '# Version: %s\n'
                 '# The remainder of this file is compressed using zlib.\n' %
                 (escape(env.config.project),
                  escape(env.config.version))).encode())
        # body
        compressor = zlib.compressobj(9)
        for domainname, domain in sorted(env.domains.items()):
            for name, dispname, typ, docname, anchor, prio in \
                    sorted(domain.get_objects()):
                if anchor.endswith(name):
                    # this can shorten the inventory by as much as 25%
                    anchor = anchor[:-len(name)] + '$'
                uri = builder.get_target_uri(docname)
                if anchor:
                    uri += '#' + anchor
                if dispname == name:
                    dispname = '-'
                entry = ('%s %s:%s %s %s %s\n' %
                         (name, domainname, typ, prio, uri, dispname))
                f.write(compressor.compress(entry.encode()))
        f.write(compressor.flush())