+6
-6
Sources/StorageKit/StorageKit.swift
+6
-6
Sources/StorageKit/StorageKit.swift
···
17
17
}
18
18
19
19
/// Returns URL constructed from specified directory
20
-
static private func getURL(for directory: Directory, fileManager: FileManager = .default) throws -> URL {
20
+
public static private func getURL(for directory: Directory, fileManager: FileManager = .default) throws -> URL {
21
21
var searchPathDirectory: FileManager.SearchPathDirectory
22
22
23
23
switch directory {
···
38
38
/// - object: the encodable struct to store
39
39
/// - directory: where to store the struct
40
40
/// - fileName: what to name the file where the struct data will be stored
41
-
static func store<T: Encodable>(_ object: T, to directory: Directory, as fileName: String, encoder: JSONEncoder = JSONEncoder(), fileManager: FileManager = .default) throws {
41
+
public static func store<T: Encodable>(_ object: T, to directory: Directory, as fileName: String, encoder: JSONEncoder = JSONEncoder(), fileManager: FileManager = .default) throws {
42
42
guard let url = try? getURL(for: directory).appendingPathComponent(fileName, isDirectory: false) else { throw StorageError.createURLError }
43
43
44
44
do {
···
59
59
/// - directory: directory where struct data is stored
60
60
/// - type: struct type (i.e. Message.self)
61
61
/// - Returns: decoded struct model(s) of data
62
-
static func retrieve<T: Decodable>(_ fileName: String, from directory: Directory, as type: T.Type, decoder: JSONDecoder = JSONDecoder(), fileManager: FileManager = .default) -> T? {
62
+
public static func retrieve<T: Decodable>(_ fileName: String, from directory: Directory, as type: T.Type, decoder: JSONDecoder = JSONDecoder(), fileManager: FileManager = .default) -> T? {
63
63
guard let url = try? getURL(for: directory).appendingPathComponent(fileName, isDirectory: false) else { return nil }
64
64
guard fileManager.fileExists(atPath: url.path) else { return nil }
65
65
guard let data = fileManager.contents(atPath: url.path) else { return nil }
···
68
68
}
69
69
70
70
/// Remove all files at specified directory
71
-
static func clear(_ directory: Directory, fileManager: FileManager = .default) throws {
71
+
public static func clear(_ directory: Directory, fileManager: FileManager = .default) throws {
72
72
let url = try getURL(for: directory)
73
73
let contents = try fileManager.contentsOfDirectory(at: url, includingPropertiesForKeys: nil, options: [])
74
74
try contents.forEach { try fileManager.removeItem(at: $0) }
75
75
}
76
76
77
77
/// Remove specified file from specified directory
78
-
static func remove(_ fileName: String, from directory: Directory, fileManager: FileManager = .default) throws {
78
+
public static func remove(_ fileName: String, from directory: Directory, fileManager: FileManager = .default) throws {
79
79
guard let url = try? getURL(for: directory).appendingPathComponent(fileName, isDirectory: false) else { throw StorageError.createURLError }
80
80
guard fileManager.fileExists(atPath: url.path) else { return }
81
81
···
88
88
89
89
/// Returns Bool indicating whether file exists at specified directory with specified file name
90
90
/// - Returns: Bool indicating whether the file exists at the specified directory with the specified name
91
-
static func fileExists(_ fileName: String, in directory: Directory, fileManager: FileManager = .default) -> Bool {
91
+
public static func fileExists(_ fileName: String, in directory: Directory, fileManager: FileManager = .default) -> Bool {
92
92
guard let url = try? getURL(for: directory).appendingPathComponent(fileName, isDirectory: false) else { return false }
93
93
return fileManager.fileExists(atPath: url.path)
94
94
}