Skip to content

Commit

Permalink
Merge pull request #463 from fintelia/less-miniz-oxide
Browse files Browse the repository at this point in the history
Remove remaining uses of miniz_oxide for decoding
  • Loading branch information
kornelski committed Feb 3, 2024
2 parents b13388f + 2bd3dc9 commit 92540b3
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/text_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@
#![warn(missing_docs)]

use crate::{chunk, encoder, DecodingError, EncodingError};
use fdeflate::BoundedDecompressionError;
use flate2::write::ZlibEncoder;
use flate2::Compression;
use miniz_oxide::inflate::{decompress_to_vec_zlib, decompress_to_vec_zlib_with_limit};
use std::{convert::TryFrom, io::Write};

/// Default decompression limit for compressed text chunks.
Expand Down Expand Up @@ -287,9 +287,9 @@ impl ZTXtChunk {
pub fn decompress_text_with_limit(&mut self, limit: usize) -> Result<(), DecodingError> {
match &self.text {
OptCompressed::Compressed(v) => {
let uncompressed_raw = match decompress_to_vec_zlib_with_limit(&v[..], limit) {
let uncompressed_raw = match fdeflate::decompress_to_vec_bounded(&v[..], limit) {
Ok(s) => s,
Err(err) if err.status == miniz_oxide::inflate::TINFLStatus::HasMoreOutput => {
Err(BoundedDecompressionError::OutputTooLarge { .. }) => {
return Err(DecodingError::from(
TextDecodingError::OutOfDecompressionSpace,
));
Expand All @@ -310,7 +310,7 @@ impl ZTXtChunk {
pub fn get_text(&self) -> Result<String, DecodingError> {
match &self.text {
OptCompressed::Compressed(v) => {
let uncompressed_raw = decompress_to_vec_zlib(&v[..])
let uncompressed_raw = fdeflate::decompress_to_vec(v)
.map_err(|_| DecodingError::from(TextDecodingError::InflationError))?;
Ok(decode_iso_8859_1(&uncompressed_raw))
}
Expand Down Expand Up @@ -457,9 +457,9 @@ impl ITXtChunk {
pub fn decompress_text_with_limit(&mut self, limit: usize) -> Result<(), DecodingError> {
match &self.text {
OptCompressed::Compressed(v) => {
let uncompressed_raw = match decompress_to_vec_zlib_with_limit(&v[..], limit) {
let uncompressed_raw = match fdeflate::decompress_to_vec_bounded(v, limit) {
Ok(s) => s,
Err(err) if err.status == miniz_oxide::inflate::TINFLStatus::HasMoreOutput => {
Err(BoundedDecompressionError::OutputTooLarge { .. }) => {
return Err(DecodingError::from(
TextDecodingError::OutOfDecompressionSpace,
));
Expand All @@ -483,7 +483,7 @@ impl ITXtChunk {
pub fn get_text(&self) -> Result<String, DecodingError> {
match &self.text {
OptCompressed::Compressed(v) => {
let uncompressed_raw = decompress_to_vec_zlib(&v[..])
let uncompressed_raw = fdeflate::decompress_to_vec(v)
.map_err(|_| DecodingError::from(TextDecodingError::InflationError))?;
String::from_utf8(uncompressed_raw)
.map_err(|_| TextDecodingError::Unrepresentable.into())
Expand Down Expand Up @@ -571,7 +571,7 @@ impl EncodableTextChunk for ITXtChunk {
} else {
match &self.text {
OptCompressed::Compressed(v) => {
let uncompressed_raw = decompress_to_vec_zlib(&v[..])
let uncompressed_raw = fdeflate::decompress_to_vec(v)
.map_err(|_| EncodingError::from(TextEncodingError::CompressionError))?;
data.extend_from_slice(&uncompressed_raw[..]);
}
Expand Down

0 comments on commit 92540b3

Please sign in to comment.