View Code? Open in Web Editor
NEW
Common code for my python programs
Home Page: https://common-py.docs.cyberjake.xyz
License: Mozilla Public License 2.0
Makefile 5.86%
Python 94.14%
common-python's Introduction
Hi there ๐ I'm Cyb3r-Jak3
๐ฏ Iโm looking to collaborate on any project as I like diving into new topics. Please reach out to me to collaborate.
๐ญ Latest releases I've contributed to
๐ท Check out what I'm currently working on
๐ My recent blog posts
common-python's People
Contributors
Watchers
common-python's Issues
Example
import os, sys, codecs
def remove_bom_inplace(path):
"""Removes BOM mark, if it exists, from a file and rewrites it in-place"""
buffer_size = 4096
bom_length = len(codecs.BOM_UTF8)
with open(path, "r+b") as fp:
chunk = fp.read(buffer_size)
if chunk.startswith(codecs.BOM_UTF8):
i = 0
chunk = chunk[bom_length:]
while chunk:
fp.seek(i)
fp.write(chunk)
i += len(chunk)
fp.seek(bom_length, os.SEEK_CUR)
chunk = fp.read(buffer_size)
fp.seek(-bom_length, os.SEEK_CUR)
fp.truncate()