I am working on my timezone library ( https://github.com/treeform/chrono ) and I would like to pack timezone definitions into the binary. I can do that with staticRead, but then I have to read the binary out of the string. My binary uses the exact same flat (no nested structures) as the seq memory. Is there a way for me to just say seq should point to the bytes from staticRead without doing any copies or reads?
Here is the code I have now which feels super complex (and stupid):
const zoneData = staticRead("../tzdata/timeZones.bin")
var timeZones* = newSeq[TimeZone](zoneData.len div sizeof(TimeZone)) ## List of all timezones
var zoneStream = newStringStream(zoneData)
for i in 0..<timeZones.len:
var dummyZone = TimeZone()
discard zoneStream.readData(cast[pointer](addr dummyZone), sizeof(TimeZone))
timeZones[i] = dummyZone
I want to have code look more like this:
var timeZones = newSeq[TimeZone](0)
var timeZonesBin = staticRead("../tzdata/timeZones.bin")
timeZone.internalPointer = addr timeZonesBin[0]
timeZone.len = timeZonesBin.len div sizeof(TimeZone)
Thanks!
Its 3MB not 6MB. So its less then linux. And its not compressed. Moment TZ implements a custom compressor for the TZ data. I have though about depending on some thing like snappy to compress the timezones db but that will add ms to startup time and extra dependency.
Do you think I should add snappy and get it as small as possible?
Python (pytz), Java (JDK), Rust (chrono-tz) also maintains its own databases. I don't think its that unusual.
Can you find an example of a language that uses system timezones on windows through win32 api (not .net)?