Polyfile Weave

0.5.9 · active · verified Sun Apr 12

Polyfile Weave is a utility designed to recursively map the structure of a file, providing a detailed breakdown of its components and their relationships. It helps in understanding complex binary formats by visualizing their internal layout. The current version is 0.5.9. Releases are infrequent, often addressing bug fixes or minor improvements.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `polyfile-weave` to analyze a dummy binary file. It creates a simple file, runs the `weave` function, and directs the output (including HTML visualizations and JSON structure) to a specified directory.

import os
from pathlib import Path
from polyfile.weave import weave

# Create a dummy file for demonstration purposes
dummy_file_content = b"This is some dummy text. It might contain some structures like PK\x03\x04 to simulate a zip header, or just plain text."
dummy_filename = "dummy_test_file.bin"
output_dir = "weave_output_results"

# Ensure the dummy file exists
if not Path(dummy_filename).exists():
    with open(dummy_filename, "wb") as f:
        f.write(dummy_file_content)

print(f"Analyzing file: '{dummy_filename}'")

try:
    # Create the output directory if it doesn't exist
    Path(output_dir).mkdir(parents=True, exist_ok=True)
    
    # Run the weaving process
    weave.weave(dummy_filename, output_dir=output_dir)
    
    print(f"Analysis complete. Detailed results are in the directory: '{output_dir}'")
    print("Look for 'index.html' or 'structure.json' within this directory.")
except Exception as e:
    print(f"An error occurred during the file weaving process: {e}")
finally:
    # Optional cleanup: remove the dummy file and output directory
    # import shutil
    # if Path(dummy_filename).exists():
    #     os.remove(dummy_filename)
    # if Path(output_dir).exists():
    #     shutil.rmtree(output_dir)
    pass

view raw JSON →