Repository: SDWebImage/SDWebImage
File: SDWebImage/SDWebImageDownloaderOperation.m (Objective-C)

Code before:
    } else {
        if ([self callbacksForKey:kCompletedCallbackKey].count > 0) {
            /**
             *  If you specified to use `NSURLCache`, then the response you get here is what you need.
             *  if you specified to only use cached data via `SDWebImageDownloaderIgnoreCachedResponse`,
             *  the response data will be nil.
             *  So we don't need to check the cache option here, since the system will obey the cache option
             */
            NSData *imageData = [self.imageData copy];
            if (imageData) {
                UIImage *image = [UIImage sd_imageWithData:imageData];
                NSString *key = [[SDWebImageManager sharedManager] cacheKeyForURL:self.request.URL];
                image = [self scaledImageForKey:key image:image];
                
                BOOL shouldDecode = YES;
                // Do not force decoding animated GIFs and WebPs
                if (image.images) {
                    shouldDecode = NO;
                } else {
#ifdef SD_WEBP
                    SDImageFormat imageFormat = [NSData sd_imageFormatForImageData:self.imageData];
                    if (imageFormat == SDImageFormatWebP) {
                        shouldDecode = NO;
                    }
#endif
                }

                if (shouldDecode) {
                    if (self.shouldDecompressImages) {
                        if (self.options & SDWebImageDownloaderScaleDownLargeImages) {
#if SD_UIKIT || SD_WATCH
                            image = [UIImage decodedAndScaledDownImageWithImage:image];
                            imageData = UIImagePNGRepresentation(image);
#endif
                        } else {
                            image = [UIImage decodedImageWithImage:image];
                        }
                    }
                }
                if (CGSizeEqualToSize(image.size, CGSizeZero)) {
                    [self callCompletionBlocksWithError:[NSError errorWithDomain:SDWebImageErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey : @"Downloaded image has 0 pixels"}]];
                } else {
                    [self callCompletionBlocksWithImage:image imageData:imageData error:nil finished:YES];
                }
            } else {
                [self callCompletionBlocksWithError:[NSError errorWithDomain:SDWebImageErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey : @"Image data is nil"}]];
            }
        }
    }
    [self done];
}

Review comment (bug):
This early return will cause logic bug. Need to call `[self done]`. Fixed via #2049 

Code after:
            [[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStopNotification object:weakSelf];
            if (!error) {
                [[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadFinishNotification object:weakSelf];
            }
        });
    }
    
    if (error) {
        [self callCompletionBlocksWithError:error];
    } else {
        if ([self callbacksForKey:kCompletedCallbackKey].count > 0) {
            /**
             *  If you specified to use `NSURLCache`, then the response you get here is what you need.
             */
            NSData *imageData = [self.imageData copy];
            if (imageData) {
                UIImage *image = [UIImage sd_imageWithData:imageData];
                /**  if you specified to only use cached data via `SDWebImageDownloaderIgnoreCachedResponse`,
                 *  then we should check if the cached data is equal to image data
                 */
                if (self.options & SDWebImageDownloaderIgnoreCachedResponse) {
                    if (self.cachedData) {
                        if ([self.cachedData isEqualToData:imageData]) {
                            // call completion block with nil
                            [self callCompletionBlocksWithImage:nil imageData:nil error:nil finished:YES];
                            return;
                        }
                    }
                }
                NSString *key = [[SDWebImageManager sharedManager] cacheKeyForURL:self.request.URL];
                image = [self scaledImageForKey:key image:image];
                
                BOOL shouldDecode = YES;
                // Do not force decoding animated GIFs and WebPs
                if (image.images) {
                    shouldDecode = NO;
                } else {
#ifdef SD_WEBP
                    SDImageFormat imageFormat = [NSData sd_imageFormatForImageData:self.imageData];
                    if (imageFormat == SDImageFormatWebP) {
                        shouldDecode = NO;
                    }
#endif
                }

                if (shouldDecode) {
                    if (self.shouldDecompressImages) {
                        if (self.options & SDWebImageDownloaderScaleDownLargeImages) {
#if SD_UIKIT || SD_WATCH
                            image = [UIImage decodedAndScaledDownImageWithImage:image];
                            imageData = UIImagePNGRepresentation(image);