aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2013-04-27 23:01:49 +0100
committerMichael Williamson <mike@zwobble.org>2013-04-27 23:01:49 +0100
commit43db35ec5e5125055fa8ccfdef17d077a63f31f9 (patch)
tree8a82c18817995606f2aca482e1240333b0b1cdb9 /lib
parente1f18ccd40a40c8f9001517c9f6aa56a797a9110 (diff)
Read [Content_Types].xml to find content types of files
Diffstat (limited to 'lib')
-rw-r--r--lib/content-types-reader.js29
-rw-r--r--lib/office-xml-reader.js3
2 files changed, 30 insertions, 2 deletions
diff --git a/lib/content-types-reader.js b/lib/content-types-reader.js
index 5240d21..0346b8c 100644
--- a/lib/content-types-reader.js
+++ b/lib/content-types-reader.js
@@ -1,10 +1,37 @@
+var readXmlFromZipFile = require("./office-xml-reader").readXmlFromZipFile;
+
exports.readContentTypesFromZipFile = readContentTypesFromZipFile;
+exports.readContentTypesFromXml = readContentTypesFromXml;
function readContentTypesFromZipFile(file) {
+ return readXmlFromZipFile(file, "[Content_Types].xml")
+ .then(function(xml) {
+ return xml ? readContentTypesFromXml(xml) : defaultContentTypes;
+ });
+}
+
+function readContentTypesFromXml(xml) {
+ var extensionDefaults = {};
+
+ xml.root.children.forEach(function(child) {
+ if (child.name === "content-types:Default") {
+ extensionDefaults[child.attributes.Extension] = child.attributes.ContentType;
+ }
+ });
+
return {
findContentType: function(path) {
- return "image/png";
+ var pathParts = path.split(".");
+ var extension = pathParts[pathParts.length - 1];
+ return extensionDefaults[extension];
}
}
}
+
+
+var defaultContentTypes = {
+ findContentType: function(path) {
+ return null;
+ }
+};
diff --git a/lib/office-xml-reader.js b/lib/office-xml-reader.js
index 7aa8bab..04b73fb 100644
--- a/lib/office-xml-reader.js
+++ b/lib/office-xml-reader.js
@@ -10,7 +10,8 @@ var xmlNamespaceMap = {
"http://schemas.openxmlformats.org/officeDocument/2006/relationships": "r",
"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing": "wp",
"http://schemas.openxmlformats.org/drawingml/2006/main": "a",
- "http://schemas.openxmlformats.org/drawingml/2006/picture": "pic"
+ "http://schemas.openxmlformats.org/drawingml/2006/picture": "pic",
+ "http://schemas.openxmlformats.org/package/2006/content-types": "content-types"
};