sbmlteam / libCombine

a C++ library for working with the COMBINE Archive format
BSD 2-Clause "Simplified" License
8 stars 5 forks source link

Add support for buffer contents #61

Closed agarny closed 3 months ago

agarny commented 1 year ago

Right now, we can initialise a COMBINE archive from a directory (using initializeFromDirectory(), although it doesn't seem to be doing anything?) or from an archive itself (using initializeFromArchive()). However, if we look at libSBML and libSEDML, we can see that we can also "initialise" an SBML/SED-ML document from a string (using readSBMLFromString() and readSedMLFromString(), respectively), which is very useful when wanting to "initialise" such a document on a website using WASM, for instance.

So, in a similar way, it would be nice if we could initialise a COMBINE archive directly from the contents of a file (most likely using a unsigned char * parameter and a size_t parameter since std::string on its own wouldn't allow us to pass the contents of a COMBINE archive).

fbergmann commented 1 year ago

Indeed, initializeFromDirectory is currently not implemented, and probably not needed. The underlying zip API uses overloads:

for support of memory streams. This could be easily used to make reading from archives possible.

That being said, I'm not sure that libCombine would properly work for WASM when creating combine archives, as it is relying on reading / writing temporary files (which would probably not work in WASM).

agarny commented 1 year ago

Argh, I clearly missed the GitHub notification since I have just seen your reply!

Indeed, initializeFromDirectory is currently not implemented, and probably not needed. The underlying zip API uses overloads:

  • std::istream& buffer and
  • std::vector<unsigned char>& buffer

for support of memory streams. This could be easily used to make reading from archives possible.

That being said, I'm not sure that libCombine would properly work for WASM when creating combine archives, as it is relying on reading / writing temporary files (which would probably not work in WASM).

Yes, to read/write temporary files shouldn't be possible in WASM. Anyway, I will see what I can do about it since I would really like to take advantage of libCombine from WASM and thus have full support for CellML / SED-ML files and COMBINE archives from the web.

So, yes, I am going to look into it and create a PR if I can come up with something useful to the community.

fbergmann commented 1 year ago

Thank you so much, in the meantime .. do you want me to expose the ways mentioned above to initialize a CombineArchive instance from stream / vector?

agarny commented 1 year ago

Thank you so much, in the meantime .. do you want me to expose the ways mentioned above to initialize a CombineArchive instance from stream / vector?

Yes, it would be nice if you could, but no pressure (seriously).