samdark / sitemap

Sitemap and sitemap index builder
BSD 3-Clause "New" or "Revised" License
530 stars 87 forks source link

What about adding saveXML or a __toString to both Sitemap and Index? #69

Open doppiogancio opened 3 years ago

doppiogancio commented 3 years ago

Hi, I found really helpful this package, but since I need to use a different writer I was wondering if its possible to add a method to export the XML as a string for both the classes Sitemap and Index.

samdark commented 3 years ago

@doppiogancio yes, that's possible but that could be resource consuming. When writing to file, it's writing each piece separately so memory usage stays low.

terales commented 3 years ago

@doppiogancio you can write to a temporary file location and then stream the contents into your desired location. Are you pushing sitemap to S3-like storage?

doppiogancio commented 3 years ago

First of all thanks to both @samdark @terales for the answers.

@doppiogancio you can write to a temporary file location and then stream the contents into your desired location. Are you pushing sitemap to S3-like storage?

Yes, I am using FlySystem. I solved the problem creating the files in a temporary folder, and only after uploading them to S3.

@samdark I understand, you are right. Having the chance to provide a new writer from the outside do you think is doable? Any concern?

samdark commented 3 years ago

Current version is quite coupled in this matter. I've started big refactoring a few years ago in https://github.com/samdark/sitemap/pull/59 but then got occupied by other things. That new version should be better about replacing writers.