Load File from Stream

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

Close
Loading

Analyzing your prompt, please hold on...

An error occurred while retrieving the results. Please refresh the page and try again.