BoxData is a lightweight byte format data serialization library. With Box, you can compress Codable
data up thousands of times lighter than JSON or Plist, and can read and write faster than those.
When I saved data below.
Type | File Size |
---|---|
Box | 155 B !!!!!! |
JSON | 5.8 MB |
Plist | 5.4 MB |
// Codable Data
struct Person: Codable {
let name: String
let age: UInt8
let birth:Conutry
struct Conutry: Codable {
let name: String
let id: UInt8
}
}
// Prepare Data
let alice = Person(name: "Alice", age: 16, birth: .init(name: "UK" , id: 12))
let bob = Person(name: "Bob" , age: 22, birth: .init(name: "America", id: 14))
/// 100000 data !!!
let people = Array(repeating: alice, count: 50000)
+ Array(repeating: bob , count: 50000)
You can use BoxEncoder
and BoxDecoder
like JSONEncoder
or PropertyListEncoder
.
do {
// encoding
let data = try BoxEncoder().encode(people)
// decoding
let decoded = try BoxDecoder().decode(Array<Person>.self, from: data)
} catch {
print(error)
}
To run the example project, clone the repo, and run pod install
from the Example directory first.
Box Format has 2 options.
-
useStructureCache
This option enable structure caching.
-
useCompression
This option enable compression.
let encoder = BoxEncoder()
// set before encode
encoder.useStructureCache = true / false
encoder.compressionLevel = 0...6
BoxData is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'BoxData'
ObuchiYuki, yukibochi1@gmail.com
BoxData is available under the MIT license. See the LICENSE file for more info.