We currently close our fbs files by killing them, so sometimes they end
        up with bad data at the end. Close our reader if we expect `size` bytes
        and get fewer.

        This is a hack and should be removed when we cleanly close our
        connections in fbs_writer.

        https://github.com/openai/universe-envs/issues/41

def read_safe(self, size=None):
        """
        We currently close our fbs files by killing them, so sometimes they end
        up with bad data at the end. Close our reader if we expect `size` bytes
        and get fewer.

        This is a hack and should be removed when we cleanly close our
        connections in fbs_writer.

        https://github.com/openai/universe-envs/issues/41
        """
        bytes = self.file.read(size)
        if len(bytes) != size:
            # We unexpectedly got to the end of the file
            self.close()
            raise StopIteration
        return bytes