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

Support for reading directly from zip files #25

Open
matt-sd-watson opened this issue Oct 30, 2023 · 2 comments
Open

Support for reading directly from zip files #25

matt-sd-watson opened this issue Oct 30, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@matt-sd-watson
Copy link

Does the readimc API for MCDFile allow for reading mcd files directly from a zipped state? Our group often compresses these files to save space, and this functionality would be great for faster data processing.

@matt-sd-watson matt-sd-watson changed the title Aupport for reading directly from zip files Support for reading directly from zip files Oct 30, 2023
@jwindhager
Copy link
Contributor

jwindhager commented Oct 30, 2023

Hi @matt-sd-watson,

This is currently not supported, but I think it would be a great addition. Tagging @Milad4849 here, the current maintainer.

With that being said, MCDFile just operates with standard file handles, so you could try to extend the MCDFile class yourself:

class MyMCDFile(MCDFile):
    def open(self) -> None:
        if self._path.name.suffix == ".zip":        
            self._fh = ZipFile(self._path).open("myfile.mcd", mode="rb")
            self._schema_xml = self._read_schema_xml()
            self._slides = MCDParser(self._schema_xml).parse_slides()
        else:
            super().open()  # call original MCDFile.open function

Note that this is untested. Not sure whether this will work as expected, especially because it will likely cause problems with memory mapping (e.g. here and here), but it may provide a starting point - I'm sure @Milad4849 would welcome pull requests! For example, one could think of modifying MCDFile.__init__ to also accept file handles, and only use memory mapping for uncompressed data.

@jwindhager jwindhager added the enhancement New feature or request label Oct 30, 2023
@Milad4849
Copy link
Contributor

Indeed as @jwindhager mentions, pull requests are very welcome :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants