Skip to content
Snippets Groups Projects
Commit e22c3daf authored by Dariusz Rybicki's avatar Dariusz Rybicki
Browse files

Update MessengerFileManager

parent c4fdba3c
Branches
Tags
2 merge requests!110Backup improvements & example,!102Release 1.0.0
......@@ -5,6 +5,9 @@ public struct MessengerFileManager {
public var isDirectoryEmpty: (String) -> Bool
public var removeItem: (String) throws -> Void
public var createDirectory: (String) throws -> Void
public var saveFile: (String, Data) throws -> Void
public var loadFile: (String) throws -> Data?
public var modifiedTime: (String) throws -> Date?
}
extension MessengerFileManager {
......@@ -26,6 +29,16 @@ extension MessengerFileManager {
atPath: path,
withIntermediateDirectories: true
)
},
saveFile: { path, data in
try data.write(to: URL(fileURLWithPath: path))
},
loadFile: { path in
try Data(contentsOf: URL(fileURLWithPath: path))
},
modifiedTime: { path in
let attributes = try fileManager.attributesOfItem(atPath: path)
return attributes[.modificationDate] as? Date
}
)
}
......@@ -35,6 +48,9 @@ extension MessengerFileManager {
public static let unimplemented = MessengerFileManager(
isDirectoryEmpty: XCTUnimplemented("\(Self.self).isDirectoryEmpty", placeholder: false),
removeItem: XCTUnimplemented("\(Self.self).removeItem"),
createDirectory: XCTUnimplemented("\(Self.self).createDirectory")
createDirectory: XCTUnimplemented("\(Self.self).createDirectory"),
saveFile: XCTUnimplemented("\(Self.self).saveFile"),
loadFile: XCTUnimplemented("\(Self.self).loadFile"),
modifiedTime: XCTUnimplemented("\(Self.self).modifiedTime")
)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment