ソースを参照

Add data getter to retrieve result

onevcat 3 年 前
コミット
3d8d24b7e7
1 ファイル変更10 行追加5 行削除
  1. 10 5
      Sources/General/KingfisherManager.swift

+ 10 - 5
Sources/General/KingfisherManager.swift

@@ -35,7 +35,6 @@ public typealias DownloadProgressBlock = ((_ receivedSize: Int64, _ totalSize: I
 
 
 /// Represents the result of a Kingfisher retrieving image task.
 /// Represents the result of a Kingfisher retrieving image task.
 public struct RetrieveImageResult {
 public struct RetrieveImageResult {
-
     /// Gets the image object of this result.
     /// Gets the image object of this result.
     public let image: KFCrossPlatformImage
     public let image: KFCrossPlatformImage
 
 
@@ -50,6 +49,8 @@ public struct RetrieveImageResult {
     /// When an alternative source loading happened, the `source` will be the replacing loading target, while the
     /// When an alternative source loading happened, the `source` will be the replacing loading target, while the
     /// `originalSource` will be kept as the initial `source` which issued the image loading process.
     /// `originalSource` will be kept as the initial `source` which issued the image loading process.
     public let originalSource: Source
     public let originalSource: Source
+    
+    public let data: () -> Data?
 }
 }
 
 
 /// A struct that stores some related information of an `KingfisherError`. It provides some context information for
 /// A struct that stores some related information of an `KingfisherError`. It provides some context information for
@@ -419,7 +420,8 @@ public class KingfisherManager {
                 image: options.imageModifier?.modify(value.image) ?? value.image,
                 image: options.imageModifier?.modify(value.image) ?? value.image,
                 cacheType: .none,
                 cacheType: .none,
                 source: source,
                 source: source,
-                originalSource: context.originalSource
+                originalSource: context.originalSource,
+                data: {  value.originalData }
             )
             )
             // Add image to cache.
             // Add image to cache.
             let targetCache = options.targetCache ?? self.cache
             let targetCache = options.targetCache ?? self.cache
@@ -561,7 +563,8 @@ public class KingfisherManager {
                                         image: image,
                                         image: image,
                                         cacheType: $0.cacheType,
                                         cacheType: $0.cacheType,
                                         source: source,
                                         source: source,
-                                        originalSource: context.originalSource
+                                        originalSource: context.originalSource,
+                                        data: { options.cacheSerializer.data(with: image, original: nil) }
                                     )
                                     )
                                 }
                                 }
                             } else {
                             } else {
@@ -624,11 +627,13 @@ public class KingfisherManager {
                             let coordinator = CacheCallbackCoordinator(
                             let coordinator = CacheCallbackCoordinator(
                                 shouldWaitForCache: options.waitForCache, shouldCacheOriginal: false)
                                 shouldWaitForCache: options.waitForCache, shouldCacheOriginal: false)
 
 
+                            let image = options.imageModifier?.modify(processedImage) ?? processedImage
                             let result = RetrieveImageResult(
                             let result = RetrieveImageResult(
-                                image: options.imageModifier?.modify(processedImage) ?? processedImage,
+                                image: image,
                                 cacheType: .none,
                                 cacheType: .none,
                                 source: source,
                                 source: source,
-                                originalSource: context.originalSource
+                                originalSource: context.originalSource,
+                                data: { options.cacheSerializer.data(with: processedImage, original: nil) }
                             )
                             )
 
 
                             targetCache.store(
                             targetCache.store(