Advertisement
Python253

bin2html

Mar 11th, 2024
628
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.24 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Filename: bin2html.py
  4. # Version: 1.0.1
  5. # Author: Jeoi Reqi
  6.  
  7. """
  8. Description:
  9. This script converts a binary file (.bin) to an HTML file (.html).
  10. It embeds the binary content within a basic HTML structure, assuming each line in the binary file represents a separate record.
  11. The script decodes each line from UTF-8 before embedding it into the HTML file.
  12.  
  13. Requirements:
  14. - Python 3.x
  15.  
  16. Usage:
  17. 1. Save this script as 'bin2html.py'.
  18. 2. Ensure your binary file ('example.bin') is in the same directory as the script.
  19. 3. Run the script.
  20. 4. The converted HTML file ('bin2html.html') will be generated in the same directory.
  21.  
  22. Note: Adjust the 'bin_filename' and 'html_filename' variables in the script as needed.
  23. """
  24.  
  25. def bin_to_html(bin_filename, html_filename):
  26.  with open(bin_filename, 'rb') as binfile, open(html_filename, 'w') as htmlfile:
  27.      # Use basic HTML structure and write binary content
  28.      htmlfile.write(f'<html><body><p>{"".join(line.decode("utf-8") for line in binfile)}</p></body></html>')
  29.  
  30. if __name__ == "__main__":
  31.  bin_filename = 'example.bin'
  32.  html_filename = 'bin2html.html'
  33.  bin_to_html(bin_filename, html_filename)
  34.  print(f"Converted '{bin_filename}' to '{html_filename}'.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement