based on upstream miniz