View Single Post
Old 11-23-2014, 12:59 PM   #12
KevinH
Wizard
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 3,101
Karma: 1931746
Join Date: Nov 2009
Device: many
Hi Toxaris,

Quote:
Originally Posted by Toxaris View Post
Another question, in the bookcontainer class (that is for edit plugins, right?)
Yes that is the container class for "edit" plugins - it was not named "editcontainer.py" because it existed before we thought of the separate plugin types, and as such it kept its original name "bookcontainer.py"

Quote:
there is a function to replace files in the ePUB after adaptation, writefile.
I need the id from the OPF and I need to input data. For text based files that would be a string I pressume. However, what if I want to replace (or add for that matter) a non-text based file like a font, audio or video? Must I use some kind of binary stream?

Can you shed some light on that?
If you are editing or changing an already existing file then "writefile" is the way to go (assuming the file is part of the manifest). The media-type field from the manifiest is used to determine what should be done with the data you want to write.

Based on the media-type if it is text (css or xhtml/xml) the data is tested to see if it is unicode or a bytestring. If a bytestring it is assumed to be utf-8, if unicode, it is converted to utf-8 and written to the output file.

Based on the media-type,if it is not text, the data is assumed to be a string of bytes and it is written (as binary) unchanged to the output file.


Now if you want to create an entirely new file that should be part of the manifest, you would use the "addfile". Here you can explicitly pass in a media-type or a media-type can be deduced from the filename extension. And again, the media-type determines how the data will be treated.

Hope this helps,

KevinH
KevinH is offline   Reply With Quote