Skip to content

Commit

Permalink
Read and write file in binary mode to remove BOM (Byte Order Mark) bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
arisktfx committed Oct 23, 2024
1 parent da3e7c2 commit 131cfd1
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions openformats/formats/docx.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def __init__(self, content):
os.remove(docx_path)

base_rels_path = '{}/{}'.format(self.__tmp_folder, '_rels/.rels')
with io.open(base_rels_path, 'r') as f:
with io.open(base_rels_path, 'rb') as f:
base_rels = f.read()

document_relative_path = next((
Expand All @@ -124,7 +124,7 @@ def __init__(self, content):

def get_document(self):
if self.__document is None:
with io.open(self.__document_path, 'r') as f:
with io.open(self.__document_path, 'rb') as f:
self.__document = f.read()

return self.__document
Expand All @@ -137,15 +137,15 @@ def set_document(self, document):

def get_document_rels(self):
if self.__document_rels is None:
with io.open(self.__document_rels_path, 'r') as f:
with io.open(self.__document_rels_path, 'rb') as f:
self.__document_rels = f.read()

return self.__document_rels

def set_document_rels(self, document_rels):
self.__document_rels = document_rels

with io.open(self.__document_rels_path, 'w') as f:
with io.open(self.__document_rels_path, 'wb') as f:
f.write(document_rels)

def compress(self):
Expand Down

0 comments on commit 131cfd1

Please sign in to comment.