diff --git a/Sources/Disk+Codable.swift b/Sources/Disk+Codable.swift index 930046f..42b345a 100644 --- a/Sources/Disk+Codable.swift +++ b/Sources/Disk+Codable.swift @@ -31,7 +31,8 @@ public extension Disk { /// - path: file location to store the data (i.e. "Folder/file.json") /// - encoder: custom JSONEncoder to encode value /// - Throws: Error if there were any issues encoding the struct or writing it to disk - static func save(_ value: T, to directory: Directory, as path: String, encoder: JSONEncoder = JSONEncoder()) throws { + @discardableResult + static func save(_ value: T, to directory: Directory, as path: String, encoder: JSONEncoder = JSONEncoder()) throws -> URL { if path.hasSuffix("/") { throw createInvalidFileNameForStructsError() } @@ -40,6 +41,7 @@ public extension Disk { let data = try encoder.encode(value) try createSubfoldersBeforeCreatingFile(at: url) try data.write(to: url, options: .atomic) + return url } catch { throw error } diff --git a/Sources/Disk+Data.swift b/Sources/Disk+Data.swift index 5a14fbf..15908df 100644 --- a/Sources/Disk+Data.swift +++ b/Sources/Disk+Data.swift @@ -30,11 +30,13 @@ public extension Disk { /// - directory: user directory to store the file in /// - path: file location to store the data (i.e. "Folder/file.mp4") /// - Throws: Error if there were any issues writing the given data to disk - static func save(_ value: Data, to directory: Directory, as path: String) throws { + @discardableResult + static func save(_ value: Data, to directory: Directory, as path: String) throws -> URL { do { let url = try createURL(for: path, in: directory) try createSubfoldersBeforeCreatingFile(at: url) try value.write(to: url, options: .atomic) + return url } catch { throw error } diff --git a/Sources/Disk+UIImage.swift b/Sources/Disk+UIImage.swift index 6ad3550..e4550ee 100644 --- a/Sources/Disk+UIImage.swift +++ b/Sources/Disk+UIImage.swift @@ -31,7 +31,8 @@ public extension Disk { /// - directory: user directory to store the image file in /// - path: file location to store the data (i.e. "Folder/file.png") /// - Throws: Error if there were any issues writing the image to disk - static func save(_ value: UIImage, to directory: Directory, as path: String) throws { + @discardableResult + static func save(_ value: UIImage, to directory: Directory, as path: String) throws -> URL { do { var imageData: Data if path.suffix(4).lowercased() == ".png" { @@ -97,6 +98,7 @@ public extension Disk { let url = try createURL(for: path, in: directory) try createSubfoldersBeforeCreatingFile(at: url) try imageData.write(to: url, options: .atomic) + return url } catch { throw error } diff --git a/Sources/Disk+[Data].swift b/Sources/Disk+[Data].swift index a3b149f..d4d1ac5 100644 --- a/Sources/Disk+[Data].swift +++ b/Sources/Disk+[Data].swift @@ -30,17 +30,21 @@ public extension Disk { /// - directory: user directory to store the files in /// - path: folder location to store the data files (i.e. "Folder/") /// - Throws: Error if there were any issues creating a folder and writing the given [Data] to files in it - static func save(_ value: [Data], to directory: Directory, as path: String) throws { + @discardableResult + static func save(_ value: [Data], to directory: Directory, as path: String) throws -> [URL] { do { let folderUrl = try createURL(for: path, in: directory) try createSubfoldersBeforeCreatingFile(at: folderUrl) try FileManager.default.createDirectory(at: folderUrl, withIntermediateDirectories: false, attributes: nil) + var urls: [URL] = [] for i in 0.. [URL] { do { let folderUrl = try createURL(for: path, in: directory) try createSubfoldersBeforeCreatingFile(at: folderUrl) try FileManager.default.createDirectory(at: folderUrl, withIntermediateDirectories: false, attributes: nil) + var urls: [URL] = [] for i in 0..