Skip to content

Commit e9b0f42

Browse files
committed
Put image wrapper back
1 parent d9c3c91 commit e9b0f42

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import Foundation
2+
3+
public struct ImageWrapper: Codable {
4+
public let image: Image
5+
6+
public enum CodingKeys: String, CodingKey {
7+
case image
8+
}
9+
10+
public init(image: Image) {
11+
self.image = image
12+
}
13+
14+
public init(from decoder: Decoder) throws {
15+
let container = try decoder.container(keyedBy: CodingKeys.self)
16+
let data = try container.decode(Data.self, forKey: CodingKeys.image)
17+
guard let image = Image(data: data) else {
18+
throw StorageError.decodingFailed
19+
}
20+
21+
self.image = image
22+
}
23+
24+
public func encode(to encoder: Encoder) throws {
25+
var container = encoder.container(keyedBy: CodingKeys.self)
26+
guard let data = image.cache_toData() else {
27+
throw StorageError.encodingFailed
28+
}
29+
30+
try container.encode(data, forKey: CodingKeys.image)
31+
}
32+
}

0 commit comments

Comments
 (0)