Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- # Filename: bin2html.py
- # Version: 1.0.1
- # Author: Jeoi Reqi
- """
- Description:
- This script converts a binary file (.bin) to an HTML file (.html).
- It embeds the binary content within a basic HTML structure, assuming each line in the binary file represents a separate record.
- The script decodes each line from UTF-8 before embedding it into the HTML file.
- Requirements:
- - Python 3.x
- Usage:
- 1. Save this script as 'bin2html.py'.
- 2. Ensure your binary file ('example.bin') is in the same directory as the script.
- 3. Run the script.
- 4. The converted HTML file ('bin2html.html') will be generated in the same directory.
- Note: Adjust the 'bin_filename' and 'html_filename' variables in the script as needed.
- """
- def bin_to_html(bin_filename, html_filename):
- with open(bin_filename, 'rb') as binfile, open(html_filename, 'w') as htmlfile:
- # Use basic HTML structure and write binary content
- htmlfile.write(f'<html><body><p>{"".join(line.decode("utf-8") for line in binfile)}</p></body></html>')
- if __name__ == "__main__":
- bin_filename = 'example.bin'
- html_filename = 'bin2html.html'
- bin_to_html(bin_filename, html_filename)
- print(f"Converted '{bin_filename}' to '{html_filename}'.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement