Skip to content

Commit

Permalink
(NEW) Added feature for selecting image format while configuring.
Browse files Browse the repository at this point in the history
  • Loading branch information
aumChauhan committed Aug 25, 2023
1 parent a74335a commit df57cb5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import PixieCacheKit
struct MyApp: App {
init() {
// Configure to use a custom directory for file-based image caching.
PixieCacheKit.configure(directoryName: "MyAppCache")
PixieCacheKit.configure(directoryName: "MyAppCache", imageFormat: .jpeg)

// OR

Expand Down
5 changes: 3 additions & 2 deletions Sources/PixieCacheKit/Internal/CacheManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public class CacheManager {

/// The name of the cache directory used by PixieCacheKit for file-based image caching.
public var cacheDirectoryName = "PixieImageCache"

public var imageFormat: ImageFormat = .jpeg

/// Create a directory if it doesn't exist at the specified path.
public func createCacheDirectory() {
// Directory path.
Expand All @@ -50,7 +51,7 @@ public class CacheManager {
private func getImagePath(key: String) -> URL? {
guard let cacheURL = getCacheDirectoryPath() else { return nil }

return cacheURL.appendingPathComponent(key + ".jpeg")
return cacheURL.appendingPathComponent(key + imageFormat.rawValue)
}

/// Append an image in the specified directory with the given key(name).
Expand Down
17 changes: 17 additions & 0 deletions Sources/PixieCacheKit/Internal/ImageFormat.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// ImageFormat.swift
//
// Author: Aum Chauhan
// Date: 25/8/2023
// GitHub: https://github.com/aum-chauhan-175

import Foundation

@available(iOS 15.0, *)
/// Enumeration representing supported image formats in PixieCacheKit.
public enum ImageFormat: String {
/// `jpeg` stores images in .jpeg format.
case jpeg = ".jpeg"

/// `png` stores images in .png format.
case png = ".png"
}
9 changes: 7 additions & 2 deletions Sources/PixieCacheKit/Public/PixieCacheKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,16 @@ public struct PixieCacheKit {
private init() { }

/// Configure PixieCacheKit to use a custom directory for file-based image caching.
/// - Parameter directoryName: The name of the custom cache directory.
public static func configure(directoryName: String) {
/// - Parameters:
/// - directoryName: The name of the custom cache directory.
/// - imageFormat: Choose the image format (`.jpeg` & `.png`) for file manager caching.
public static func configure(directoryName: String, imageFormat: ImageFormat) {
// Configuring directory name
CacheManager.shared.cacheDirectoryName = directoryName

// Configuring image format
CacheManager.shared.imageFormat = imageFormat

// Configuring storage location.
CacheManager.shared.storageLocation = .fileManager

Expand Down

0 comments on commit df57cb5

Please sign in to comment.