Skip to content

Conversation

@rithvikgrandhi
Copy link

This PR introduces the ability to generate diagrams in-memory using a BytesIO object. This is useful for applications that require diagram generation without writing to the filesystem, such as web services or cloud functions.

Changes

  • Added an output_buffer parameter to the Diagram class.
  • Modified the render method to write to the output_buffer if provided.
  • Updated the __exit__ method to handle in-memory diagrams.

Testing

  • Verified that diagrams can be generated and rendered in-memory.
  • Ensured that existing functionality remains unaffected when output_buffer is not used.

Example Usage

from diagrams import Diagram
from io import BytesIO

output_buffer = BytesIO()
with Diagram("Example", output_buffer=output_buffer):
    # Add nodes and edges here
output_buffer.seek(0)
# The diagram is now in the output_buffer

@gabriel-tessier gabriel-tessier added the kind/feature New feature or request label Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants