diff --git a/ConversationsClassic/AppCore/Files/DownloadManager.swift b/ConversationsClassic/AppCore/Files/DownloadManager.swift new file mode 100644 index 0000000..f548244 --- /dev/null +++ b/ConversationsClassic/AppCore/Files/DownloadManager.swift @@ -0,0 +1,26 @@ +import Foundation + +final class DownloadManager { + private let urlSession: URLSession + + init() { + let configuration = URLSessionConfiguration.default + urlSession = URLSession(configuration: configuration) + } + + func download(from url: URL, to localUrl: URL, completion: @escaping (Error?) -> Void) { + let task = urlSession.downloadTask(with: url) { tempLocalUrl, _, error in + if let tempLocalUrl = tempLocalUrl, error == nil { + do { + try FileManager.default.copyItem(at: tempLocalUrl, to: localUrl) + completion(nil) + } catch let writeError { + completion(writeError) + } + } else { + completion(error) + } + } + task.resume() + } +} diff --git a/ConversationsClassic/AppCore/Files/FileManager.swift b/ConversationsClassic/AppCore/Files/FileManager.swift new file mode 100644 index 0000000..8ee7823 --- /dev/null +++ b/ConversationsClassic/AppCore/Files/FileManager.swift @@ -0,0 +1,3 @@ +import Foundation + +final class FileManager {} diff --git a/ConversationsClassic/AppCore/Middlewares/FileMiddleware.swift b/ConversationsClassic/AppCore/Middlewares/FileMiddleware.swift index fcac91b..ac69cc9 100644 --- a/ConversationsClassic/AppCore/Middlewares/FileMiddleware.swift +++ b/ConversationsClassic/AppCore/Middlewares/FileMiddleware.swift @@ -69,28 +69,3 @@ private extension FileMiddleware { return documentsURL.appendingPathComponent(Const.fileFolder) } } - -private final class DownloadManager { - private let urlSession: URLSession - - init() { - let configuration = URLSessionConfiguration.default - urlSession = URLSession(configuration: configuration) - } - - func download(from url: URL, to localUrl: URL, completion: @escaping (Error?) -> Void) { - let task = urlSession.downloadTask(with: url) { tempLocalUrl, _, error in - if let tempLocalUrl = tempLocalUrl, error == nil { - do { - try FileManager.default.copyItem(at: tempLocalUrl, to: localUrl) - completion(nil) - } catch let writeError { - completion(writeError) - } - } else { - completion(error) - } - } - task.resume() - } -}