Why no BlobItem?
kelson42 opened this issue · comments
Searching how to write blobs, i wonder why there is no BlobItem
and BlobProvider
?! https://libzim.readthedocs.io/en/latest/api/classzim_1_1writer_1_1ContentProvider.html#exhale-class-classzim-1-1writer-1-1contentprovider
The question is more "Why would we need a BlobItem
and a BlobProvider
?"
Blob
is a small wrapper around a data and a size. You can create is with Blob(const char *data, size_type size)
@mgautierfr So it's straight to write a string, how to straightly write a blob (like a png content for example)? Do I need to create a a new dedicated contentProvider?
What do you means by "write" a string ?
Adding a item with a content (as a string) into a zim ?
std::string
is just a container for char. You can put your png content is a string[*] and you are good (at least, as good as for other content)
[*] There is just a trap, you have to use the version "4" of the constructor (in this doc) and not the version "5" as the png content may contain 0
bytes.
If you don't want to put your content in a string, yes, you have to create a ContentProvider
creating Blob
from your data/size.
@mgautierfr Putting a blob in a string is a hack. A string is not (only) a char*. Actually we, with @kelvinhammond are a bit lost on node-libzim because this is unclear. We have tried to put blob in in the StringItem
but somehow the binary code get corrupted and almost all our pictures are broken. It seems to me it would be really better to just provide a BlobItem
and BlobContentProvider
would be far more user friendly.
the binary code get corrupted and almost all our pictures are broken
This is probably because your create the string with std::string(data)
. With this version of the constructor, the data will stop at the first 0
byte. You should use std::string(data, size)
If you have a data and a size, you can simply create a contentProvider on a string using:
StringProvider(std::string(data, size))
.
We could indeed create a constructor StringProvider(data, size)
which create the std::string
for you.