joeyaurel / python-gedcom

Python module for parsing, analyzing, and manipulating GEDCOM files
https://gedcom.joeyaurel.dev
GNU General Public License v2.0
154 stars 39 forks source link

Allow parser to accept files directly, not just the filepath #32

Open tsloan1377 opened 4 years ago

tsloan1377 commented 4 years ago

Currently the Parser parse_file function accepts only a file path parse_file(self, file_path, strict=True) but it would be interesting to be able to pass data directly, to be compatible with a cloud storage service.

For some context, I am trying to use the package in a web application on GCS, but running into a fundamental issue I described on Stack Overflow.

Looking at the code, it appears it could work if we could pass gedcom_file as a data object directly to be parsed line by line with self.__parse_line, rather than requiring the file be loaded from disk using gedcom_file = open(file_path, 'rb')

But maybe there's another work-around I haven't thought of?

Herst commented 4 years ago

Haven't looked at this code but maybe you could also wrap the input into an io.BytesIO/io.StringIO object.