Load File from Stream

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Comparison MCP server lets your agent work with files on your machine; they are never uploaded. It needs the .NET 10 SDK or Docker.

claude mcp add groupdocs-comparison -- dnx GroupDocs.Comparison.Mcp --yes
Folders, licensing and more →

To avoid persisting intermediate files, work with file streams directly. Pass an open binary stream to Comparer and add().

  1. Open the source and target files as binary streams.
  2. Pass the source stream to the Comparer constructor.
  3. Pass the target stream to add().
  4. Call compare() with the result path or output stream.

Example: Load files from streams

from groupdocs.comparison import Comparer

def load_file_from_stream():
    with open("./source.docx", "rb") as source_stream, \
         open("./target.docx", "rb") as target_stream:
        with Comparer(source_stream) as comparer:
            comparer.add(target_stream)
            comparer.compare("./result.docx")
            print("Documents compared successfully. Check output in result.docx.")

if __name__ == "__main__":
    load_file_from_stream()

source.docx is the source file used in this example. Click here to download it.

target.docx is the target file used in this example. Click here to download it.

Binary file (DOCX, 25 KB)

Download full output