@KevinH: Does bk.addfile() support bytearrays?
I did a quick test and came up with the following proof-of-concept code, which will add a
blackletter ttf font located in the plugin's directory to the epub:
Code:
#!/usr/bin/env python
import os, inspect, uuid
def run(bk):
basename = 'WallauRundgotisch-Heavy.ttf'
binary_path = os.path.join(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))), basename)
file_handle = open(binary_path, 'rb')
uniqueid = 'id' + str(uuid.uuid4())[24:82]
data = bytearray(file_handle.read())
file_handle.close()
mime = 'application/x-font-ttf'
bk.addfile(uniqueid, basename, data, mime)
return 0
def main():
print('I reached main when I should not have\n')
return -1
if __name__ == "__main__":
sys.exit(main())
This code appears to be working, but I'm wondering if there is a better and/or more desirable method to add binary files?