mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 06:35:51 +00:00
refactor and cleanup [skip ci]
This commit is contained in:
25
submodules/Postbox/Sources/SharedAccountMediaManager.swift
Normal file
25
submodules/Postbox/Sources/SharedAccountMediaManager.swift
Normal file
@@ -0,0 +1,25 @@
|
||||
import Foundation
|
||||
|
||||
final class SharedAccountMediaManager {
|
||||
private let basePath: String
|
||||
|
||||
init(basePath: String) {
|
||||
self.basePath = basePath
|
||||
}
|
||||
|
||||
private func fileNameForId(_ id: MediaResourceId) -> String {
|
||||
return "\(id.uniqueId)"
|
||||
}
|
||||
|
||||
private func pathForId(_ id: MediaResourceId) -> String {
|
||||
return "\(self.basePath)/\(fileNameForId(id))"
|
||||
}
|
||||
|
||||
func resourceData(resourceId: MediaResourceId) -> Data? {
|
||||
return try? Data(contentsOf: URL(fileURLWithPath: self.pathForId(resourceId)))
|
||||
}
|
||||
|
||||
func storeResourceData(resourceId: MediaResourceId, data: Data) {
|
||||
let _ = try? data.write(to: URL(fileURLWithPath: self.pathForId(resourceId)))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user