aboutsummaryrefslogtreecommitdiff
path: root/mammoth
diff options
context:
space:
mode:
Diffstat (limited to 'mammoth')
-rw-r--r--mammoth/docx/style_map.py17
-rw-r--r--mammoth/zips.py6
2 files changed, 23 insertions, 0 deletions
diff --git a/mammoth/docx/style_map.py b/mammoth/docx/style_map.py
new file mode 100644
index 0000000..2841830
--- /dev/null
+++ b/mammoth/docx/style_map.py
@@ -0,0 +1,17 @@
+from ..zips import open_zip
+
+
+_style_map_path = "mammoth/style-map"
+
+
+def write_style_map(fileobj, style_map):
+ with open_zip(fileobj, "a") as zip_file:
+ zip_file.write_str(_style_map_path, style_map)
+
+
+def read_style_map(fileobj):
+ with open_zip(fileobj, "r") as zip_file:
+ if zip_file.exists(_style_map_path):
+ return zip_file.read_str(_style_map_path)
+
+
diff --git a/mammoth/zips.py b/mammoth/zips.py
index c6fe358..24c6b1c 100644
--- a/mammoth/zips.py
+++ b/mammoth/zips.py
@@ -26,3 +26,9 @@ class _Zip(object):
return True
except KeyError:
return False
+
+ def write_str(self, name, value):
+ self._zip_file.writestr(name, value)
+
+ def read_str(self, name):
+ return self._zip_file.read(name).decode("utf8")