Load file from stream

On this page

To avoid the saving stream as a file, GroupDocs.Comparison allows you to work with file streams directly.

To work with a stream, follow these steps:

  1. Obtain a file stream.
  2. Pass the opened source file stream to the Comparer class constructor or pass the opened target file stream to the add() method.

The following code snippet shows how to load a file from a stream:

import groupdocs.comparison as gc

def load_file_from_stream(output_file_path, source_file_path, target_file_path):  
    with open(source_file_path, 'rb') as source_stream:
        with gc.Comparer(source_stream) as comparer:
            # Add the target document for comparison using a file stream
            with open(target_file_path, 'rb') as target_stream:
                comparer.add(target_stream)
            
                # Compare the documents and save the result
                comparer.compare(output_file_path)
    
    # Log the success message with the output file path
    print(f"\nDocuments compared successfully.\nCheck output in {output_file_path}.")

On this page