Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why no BlobItem? #803

Open
kelson42 opened this issue Jun 4, 2023 · 6 comments
Open

Why no BlobItem? #803

kelson42 opened this issue Jun 4, 2023 · 6 comments
Assignees
Labels
Milestone

Comments

@kelson42
Copy link
Contributor

kelson42 commented Jun 4, 2023

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

@kelson42 kelson42 added this to the 8.3.0 milestone Jun 4, 2023
@mgautierfr
Copy link
Collaborator

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)

@kelson42
Copy link
Contributor Author

kelson42 commented Jun 7, 2023

@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?

@mgautierfr
Copy link
Collaborator

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.

@kelson42
Copy link
Contributor Author

kelson42 commented Jun 7, 2023

@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.

@mgautierfr
Copy link
Collaborator

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)

@mgautierfr
Copy link
Collaborator

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.

@kelson42 kelson42 modified the milestones: 9.0.0, 9.1.0 Sep 26, 2023
@kelson42 kelson42 modified the milestones: 9.1.0, 10.0.0 Nov 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants