Skip to content

Commit

Permalink
Enoder to return nil instead of an empty data if encoding fails
Browse files Browse the repository at this point in the history
  • Loading branch information
kean committed Apr 21, 2024
1 parent cd3e07e commit 7d7efed
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion Sources/Nuke/Encoding/ImageEncoders+ImageIO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ extension ImageEncoders {
return nil
}
CGImageDestinationAddImage(destination, source, options as CFDictionary)
CGImageDestinationFinalize(destination)
guard CGImageDestinationFinalize(destination) else {
return nil
}
return data as Data
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Nuke/Tasks/TaskLoadImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ final class TaskLoadImage: ImagePipelineTask<ImageResponse> {
}
guard let data = encodedData else { return }
pipeline.delegate.willCache(data: data, image: response.container, for: request, pipeline: pipeline) {
guard let data = $0 else { return }
guard let data = $0, !data.isEmpty else { return }
// Important! Storing directly ignoring `ImageRequest.Options`.
dataCache.storeData(data, for: key) // This is instant, writes are async
}
Expand Down

0 comments on commit 7d7efed

Please sign in to comment.