bodoni / svg

Composer and parser for SVG
Other
302 stars 44 forks source link

Added method to load / save from arbitrary target, not only files #5

Closed fschutt closed 7 years ago

fschutt commented 7 years ago

Added open_from() and save_to methods to load anything that implements std::io::Read. Does not break existing code. Needed for streaming SVG / being generic over the input method.

IvanUkhov commented 7 years ago

This code is in a way redundant because all the interfaces that load and save are using right now are public. One doesn’t have to work with files. If the content to parse is already in memory, one can instantiate Parser directly. Similarly, if the content is to be stored in memory, one can just rely on Display to that end. However, these two new functions, read and write, might be useful in order to make it more obvious. They can be handy shortcuts just as load and save are.

fschutt commented 7 years ago

Should have fixed the styling issues. No idea how to test the save method, there's no documentation on how to actually get "Node" elements. Somehow I need a Node, which is only implemented for Element, but I can't get any elements from the read document, only "Events" - it's a convoluted mess.

If you could fix that, that'd be great, because I don't know how to read a document and then immediately save it again, the documentation isn't clear enough.

IvanUkhov commented 7 years ago

Thanks for your work!

Regarding save, I’m not sure why you wanted to test it as technically you hadn’t touched it. Did you mean write? In any case, Node is implemented for a bunch of structs, and you can create an Element yourself as it is shown in the first example given in the documentation. Or have I misunderstood you?