Revert "Shrink the PngError type"
This reverts commit 76c74841b49d0b7a88a0069c7a801f954b7a9f79.
This commit is contained in:
parent
fa6f3145aa
commit
ad72c37834
3 changed files with 6 additions and 10 deletions
|
|
@ -15,9 +15,9 @@ pub enum PngError {
|
|||
InvalidData,
|
||||
InvalidDepthForType(BitDepth, ColorType),
|
||||
NotPNG,
|
||||
ReadFailed(Box<str>, std::io::Error),
|
||||
ReadFailed(String, std::io::Error),
|
||||
TruncatedData,
|
||||
WriteFailed(Box<str>, std::io::Error),
|
||||
WriteFailed(String, std::io::Error),
|
||||
Other(Box<str>),
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -257,9 +257,8 @@ pub fn optimize(input: &InFile, output: &OutFile, opts: &Options) -> PngResult<(
|
|||
let output_path = path
|
||||
.as_ref()
|
||||
.map_or_else(|| input.path().unwrap(), PathBuf::as_path);
|
||||
let out_file = File::create(output_path).map_err(|err| {
|
||||
PngError::WriteFailed(output_path.display().to_string().into_boxed_str(), err)
|
||||
})?;
|
||||
let out_file = File::create(output_path)
|
||||
.map_err(|err| PngError::WriteFailed(output_path.display().to_string(), err))?;
|
||||
if let Some(metadata_input) = &opt_metadata_preserved {
|
||||
copy_permissions(metadata_input, &out_file)?;
|
||||
}
|
||||
|
|
@ -269,9 +268,7 @@ pub fn optimize(input: &InFile, output: &OutFile, opts: &Options) -> PngResult<(
|
|||
.write_all(&optimized_output)
|
||||
// flush BufWriter so IO errors don't get swallowed silently on close() by drop!
|
||||
.and_then(|()| buffer.flush())
|
||||
.map_err(|e| {
|
||||
PngError::WriteFailed(output_path.display().to_string().into_boxed_str(), e)
|
||||
})?;
|
||||
.map_err(|e| PngError::WriteFailed(output_path.display().to_string(), e))?;
|
||||
// force drop and thereby closing of file handle before modifying any timestamp
|
||||
std::mem::drop(buffer);
|
||||
if let Some(metadata_input) = &opt_metadata_preserved {
|
||||
|
|
|
|||
|
|
@ -52,8 +52,7 @@ impl PngData {
|
|||
}
|
||||
|
||||
pub fn read_file(filepath: &Path) -> PngResult<Vec<u8>> {
|
||||
fs::read(filepath)
|
||||
.map_err(|e| PngError::ReadFailed(filepath.display().to_string().into_boxed_str(), e))
|
||||
fs::read(filepath).map_err(|e| PngError::ReadFailed(filepath.display().to_string(), e))
|
||||
}
|
||||
|
||||
/// Create a new `PngData` struct by reading a slice
|
||||
|
|
|
|||
Loading…
Reference in a new issue