kreuzberg 4.0.0.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (265) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +8 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yaml +534 -0
  5. data/Gemfile +9 -0
  6. data/Gemfile.lock +157 -0
  7. data/README.md +421 -0
  8. data/Rakefile +25 -0
  9. data/Steepfile +47 -0
  10. data/examples/async_patterns.rb +340 -0
  11. data/ext/kreuzberg_rb/extconf.rb +35 -0
  12. data/ext/kreuzberg_rb/native/Cargo.toml +36 -0
  13. data/ext/kreuzberg_rb/native/README.md +425 -0
  14. data/ext/kreuzberg_rb/native/build.rs +17 -0
  15. data/ext/kreuzberg_rb/native/include/ieeefp.h +11 -0
  16. data/ext/kreuzberg_rb/native/include/msvc_compat/strings.h +14 -0
  17. data/ext/kreuzberg_rb/native/include/strings.h +20 -0
  18. data/ext/kreuzberg_rb/native/include/unistd.h +47 -0
  19. data/ext/kreuzberg_rb/native/src/lib.rs +2939 -0
  20. data/extconf.rb +28 -0
  21. data/kreuzberg.gemspec +105 -0
  22. data/lib/kreuzberg/api_proxy.rb +142 -0
  23. data/lib/kreuzberg/cache_api.rb +45 -0
  24. data/lib/kreuzberg/cli.rb +55 -0
  25. data/lib/kreuzberg/cli_proxy.rb +127 -0
  26. data/lib/kreuzberg/config.rb +684 -0
  27. data/lib/kreuzberg/errors.rb +50 -0
  28. data/lib/kreuzberg/extraction_api.rb +84 -0
  29. data/lib/kreuzberg/mcp_proxy.rb +186 -0
  30. data/lib/kreuzberg/ocr_backend_protocol.rb +113 -0
  31. data/lib/kreuzberg/post_processor_protocol.rb +86 -0
  32. data/lib/kreuzberg/result.rb +216 -0
  33. data/lib/kreuzberg/setup_lib_path.rb +79 -0
  34. data/lib/kreuzberg/validator_protocol.rb +89 -0
  35. data/lib/kreuzberg/version.rb +5 -0
  36. data/lib/kreuzberg.rb +82 -0
  37. data/pkg/kreuzberg-4.0.0.rc1.gem +0 -0
  38. data/sig/kreuzberg/internal.rbs +184 -0
  39. data/sig/kreuzberg.rbs +468 -0
  40. data/spec/binding/cache_spec.rb +227 -0
  41. data/spec/binding/cli_proxy_spec.rb +87 -0
  42. data/spec/binding/cli_spec.rb +54 -0
  43. data/spec/binding/config_spec.rb +345 -0
  44. data/spec/binding/config_validation_spec.rb +283 -0
  45. data/spec/binding/error_handling_spec.rb +213 -0
  46. data/spec/binding/errors_spec.rb +66 -0
  47. data/spec/binding/plugins/ocr_backend_spec.rb +307 -0
  48. data/spec/binding/plugins/postprocessor_spec.rb +269 -0
  49. data/spec/binding/plugins/validator_spec.rb +274 -0
  50. data/spec/examples.txt +104 -0
  51. data/spec/fixtures/config.toml +39 -0
  52. data/spec/fixtures/config.yaml +42 -0
  53. data/spec/fixtures/invalid_config.toml +4 -0
  54. data/spec/smoke/package_spec.rb +178 -0
  55. data/spec/spec_helper.rb +42 -0
  56. data/vendor/kreuzberg/Cargo.toml +134 -0
  57. data/vendor/kreuzberg/README.md +175 -0
  58. data/vendor/kreuzberg/build.rs +460 -0
  59. data/vendor/kreuzberg/src/api/error.rs +81 -0
  60. data/vendor/kreuzberg/src/api/handlers.rs +199 -0
  61. data/vendor/kreuzberg/src/api/mod.rs +79 -0
  62. data/vendor/kreuzberg/src/api/server.rs +353 -0
  63. data/vendor/kreuzberg/src/api/types.rs +170 -0
  64. data/vendor/kreuzberg/src/bin/profile_extract.rs +455 -0
  65. data/vendor/kreuzberg/src/cache/mod.rs +1143 -0
  66. data/vendor/kreuzberg/src/chunking/mod.rs +677 -0
  67. data/vendor/kreuzberg/src/core/batch_mode.rs +35 -0
  68. data/vendor/kreuzberg/src/core/config.rs +1032 -0
  69. data/vendor/kreuzberg/src/core/extractor.rs +903 -0
  70. data/vendor/kreuzberg/src/core/io.rs +327 -0
  71. data/vendor/kreuzberg/src/core/mime.rs +615 -0
  72. data/vendor/kreuzberg/src/core/mod.rs +42 -0
  73. data/vendor/kreuzberg/src/core/pipeline.rs +906 -0
  74. data/vendor/kreuzberg/src/embeddings.rs +323 -0
  75. data/vendor/kreuzberg/src/error.rs +431 -0
  76. data/vendor/kreuzberg/src/extraction/archive.rs +954 -0
  77. data/vendor/kreuzberg/src/extraction/docx.rs +40 -0
  78. data/vendor/kreuzberg/src/extraction/email.rs +854 -0
  79. data/vendor/kreuzberg/src/extraction/excel.rs +688 -0
  80. data/vendor/kreuzberg/src/extraction/html.rs +553 -0
  81. data/vendor/kreuzberg/src/extraction/image.rs +368 -0
  82. data/vendor/kreuzberg/src/extraction/libreoffice.rs +564 -0
  83. data/vendor/kreuzberg/src/extraction/mod.rs +77 -0
  84. data/vendor/kreuzberg/src/extraction/office_metadata/app_properties.rs +398 -0
  85. data/vendor/kreuzberg/src/extraction/office_metadata/core_properties.rs +247 -0
  86. data/vendor/kreuzberg/src/extraction/office_metadata/custom_properties.rs +240 -0
  87. data/vendor/kreuzberg/src/extraction/office_metadata/mod.rs +128 -0
  88. data/vendor/kreuzberg/src/extraction/pandoc/batch.rs +275 -0
  89. data/vendor/kreuzberg/src/extraction/pandoc/mime_types.rs +178 -0
  90. data/vendor/kreuzberg/src/extraction/pandoc/mod.rs +491 -0
  91. data/vendor/kreuzberg/src/extraction/pandoc/server.rs +496 -0
  92. data/vendor/kreuzberg/src/extraction/pandoc/subprocess.rs +1188 -0
  93. data/vendor/kreuzberg/src/extraction/pandoc/version.rs +162 -0
  94. data/vendor/kreuzberg/src/extraction/pptx.rs +3000 -0
  95. data/vendor/kreuzberg/src/extraction/structured.rs +490 -0
  96. data/vendor/kreuzberg/src/extraction/table.rs +328 -0
  97. data/vendor/kreuzberg/src/extraction/text.rs +269 -0
  98. data/vendor/kreuzberg/src/extraction/xml.rs +333 -0
  99. data/vendor/kreuzberg/src/extractors/archive.rs +425 -0
  100. data/vendor/kreuzberg/src/extractors/docx.rs +479 -0
  101. data/vendor/kreuzberg/src/extractors/email.rs +129 -0
  102. data/vendor/kreuzberg/src/extractors/excel.rs +344 -0
  103. data/vendor/kreuzberg/src/extractors/html.rs +410 -0
  104. data/vendor/kreuzberg/src/extractors/image.rs +195 -0
  105. data/vendor/kreuzberg/src/extractors/mod.rs +268 -0
  106. data/vendor/kreuzberg/src/extractors/pandoc.rs +201 -0
  107. data/vendor/kreuzberg/src/extractors/pdf.rs +496 -0
  108. data/vendor/kreuzberg/src/extractors/pptx.rs +234 -0
  109. data/vendor/kreuzberg/src/extractors/structured.rs +126 -0
  110. data/vendor/kreuzberg/src/extractors/text.rs +242 -0
  111. data/vendor/kreuzberg/src/extractors/xml.rs +128 -0
  112. data/vendor/kreuzberg/src/image/dpi.rs +164 -0
  113. data/vendor/kreuzberg/src/image/mod.rs +6 -0
  114. data/vendor/kreuzberg/src/image/preprocessing.rs +417 -0
  115. data/vendor/kreuzberg/src/image/resize.rs +89 -0
  116. data/vendor/kreuzberg/src/keywords/config.rs +154 -0
  117. data/vendor/kreuzberg/src/keywords/mod.rs +237 -0
  118. data/vendor/kreuzberg/src/keywords/processor.rs +267 -0
  119. data/vendor/kreuzberg/src/keywords/rake.rs +294 -0
  120. data/vendor/kreuzberg/src/keywords/types.rs +68 -0
  121. data/vendor/kreuzberg/src/keywords/yake.rs +163 -0
  122. data/vendor/kreuzberg/src/language_detection/mod.rs +942 -0
  123. data/vendor/kreuzberg/src/lib.rs +102 -0
  124. data/vendor/kreuzberg/src/mcp/mod.rs +32 -0
  125. data/vendor/kreuzberg/src/mcp/server.rs +1966 -0
  126. data/vendor/kreuzberg/src/ocr/cache.rs +469 -0
  127. data/vendor/kreuzberg/src/ocr/error.rs +37 -0
  128. data/vendor/kreuzberg/src/ocr/hocr.rs +216 -0
  129. data/vendor/kreuzberg/src/ocr/mod.rs +58 -0
  130. data/vendor/kreuzberg/src/ocr/processor.rs +847 -0
  131. data/vendor/kreuzberg/src/ocr/table/mod.rs +4 -0
  132. data/vendor/kreuzberg/src/ocr/table/tsv_parser.rs +144 -0
  133. data/vendor/kreuzberg/src/ocr/tesseract_backend.rs +450 -0
  134. data/vendor/kreuzberg/src/ocr/types.rs +393 -0
  135. data/vendor/kreuzberg/src/ocr/utils.rs +47 -0
  136. data/vendor/kreuzberg/src/ocr/validation.rs +206 -0
  137. data/vendor/kreuzberg/src/pdf/error.rs +122 -0
  138. data/vendor/kreuzberg/src/pdf/images.rs +139 -0
  139. data/vendor/kreuzberg/src/pdf/metadata.rs +346 -0
  140. data/vendor/kreuzberg/src/pdf/mod.rs +50 -0
  141. data/vendor/kreuzberg/src/pdf/rendering.rs +369 -0
  142. data/vendor/kreuzberg/src/pdf/table.rs +420 -0
  143. data/vendor/kreuzberg/src/pdf/text.rs +161 -0
  144. data/vendor/kreuzberg/src/plugins/extractor.rs +1010 -0
  145. data/vendor/kreuzberg/src/plugins/mod.rs +209 -0
  146. data/vendor/kreuzberg/src/plugins/ocr.rs +629 -0
  147. data/vendor/kreuzberg/src/plugins/processor.rs +641 -0
  148. data/vendor/kreuzberg/src/plugins/registry.rs +1324 -0
  149. data/vendor/kreuzberg/src/plugins/traits.rs +258 -0
  150. data/vendor/kreuzberg/src/plugins/validator.rs +955 -0
  151. data/vendor/kreuzberg/src/stopwords/mod.rs +1470 -0
  152. data/vendor/kreuzberg/src/text/mod.rs +19 -0
  153. data/vendor/kreuzberg/src/text/quality.rs +697 -0
  154. data/vendor/kreuzberg/src/text/string_utils.rs +217 -0
  155. data/vendor/kreuzberg/src/text/token_reduction/cjk_utils.rs +164 -0
  156. data/vendor/kreuzberg/src/text/token_reduction/config.rs +100 -0
  157. data/vendor/kreuzberg/src/text/token_reduction/core.rs +796 -0
  158. data/vendor/kreuzberg/src/text/token_reduction/filters.rs +902 -0
  159. data/vendor/kreuzberg/src/text/token_reduction/mod.rs +160 -0
  160. data/vendor/kreuzberg/src/text/token_reduction/semantic.rs +619 -0
  161. data/vendor/kreuzberg/src/text/token_reduction/simd_text.rs +147 -0
  162. data/vendor/kreuzberg/src/types.rs +873 -0
  163. data/vendor/kreuzberg/src/utils/mod.rs +17 -0
  164. data/vendor/kreuzberg/src/utils/quality.rs +959 -0
  165. data/vendor/kreuzberg/src/utils/string_utils.rs +381 -0
  166. data/vendor/kreuzberg/stopwords/af_stopwords.json +53 -0
  167. data/vendor/kreuzberg/stopwords/ar_stopwords.json +482 -0
  168. data/vendor/kreuzberg/stopwords/bg_stopwords.json +261 -0
  169. data/vendor/kreuzberg/stopwords/bn_stopwords.json +400 -0
  170. data/vendor/kreuzberg/stopwords/br_stopwords.json +1205 -0
  171. data/vendor/kreuzberg/stopwords/ca_stopwords.json +280 -0
  172. data/vendor/kreuzberg/stopwords/cs_stopwords.json +425 -0
  173. data/vendor/kreuzberg/stopwords/da_stopwords.json +172 -0
  174. data/vendor/kreuzberg/stopwords/de_stopwords.json +622 -0
  175. data/vendor/kreuzberg/stopwords/el_stopwords.json +849 -0
  176. data/vendor/kreuzberg/stopwords/en_stopwords.json +1300 -0
  177. data/vendor/kreuzberg/stopwords/eo_stopwords.json +175 -0
  178. data/vendor/kreuzberg/stopwords/es_stopwords.json +734 -0
  179. data/vendor/kreuzberg/stopwords/et_stopwords.json +37 -0
  180. data/vendor/kreuzberg/stopwords/eu_stopwords.json +100 -0
  181. data/vendor/kreuzberg/stopwords/fa_stopwords.json +801 -0
  182. data/vendor/kreuzberg/stopwords/fi_stopwords.json +849 -0
  183. data/vendor/kreuzberg/stopwords/fr_stopwords.json +693 -0
  184. data/vendor/kreuzberg/stopwords/ga_stopwords.json +111 -0
  185. data/vendor/kreuzberg/stopwords/gl_stopwords.json +162 -0
  186. data/vendor/kreuzberg/stopwords/gu_stopwords.json +226 -0
  187. data/vendor/kreuzberg/stopwords/ha_stopwords.json +41 -0
  188. data/vendor/kreuzberg/stopwords/he_stopwords.json +196 -0
  189. data/vendor/kreuzberg/stopwords/hi_stopwords.json +227 -0
  190. data/vendor/kreuzberg/stopwords/hr_stopwords.json +181 -0
  191. data/vendor/kreuzberg/stopwords/hu_stopwords.json +791 -0
  192. data/vendor/kreuzberg/stopwords/hy_stopwords.json +47 -0
  193. data/vendor/kreuzberg/stopwords/id_stopwords.json +760 -0
  194. data/vendor/kreuzberg/stopwords/it_stopwords.json +634 -0
  195. data/vendor/kreuzberg/stopwords/ja_stopwords.json +136 -0
  196. data/vendor/kreuzberg/stopwords/kn_stopwords.json +84 -0
  197. data/vendor/kreuzberg/stopwords/ko_stopwords.json +681 -0
  198. data/vendor/kreuzberg/stopwords/ku_stopwords.json +64 -0
  199. data/vendor/kreuzberg/stopwords/la_stopwords.json +51 -0
  200. data/vendor/kreuzberg/stopwords/lt_stopwords.json +476 -0
  201. data/vendor/kreuzberg/stopwords/lv_stopwords.json +163 -0
  202. data/vendor/kreuzberg/stopwords/ml_stopwords.json +1 -0
  203. data/vendor/kreuzberg/stopwords/mr_stopwords.json +101 -0
  204. data/vendor/kreuzberg/stopwords/ms_stopwords.json +477 -0
  205. data/vendor/kreuzberg/stopwords/ne_stopwords.json +490 -0
  206. data/vendor/kreuzberg/stopwords/nl_stopwords.json +415 -0
  207. data/vendor/kreuzberg/stopwords/no_stopwords.json +223 -0
  208. data/vendor/kreuzberg/stopwords/pl_stopwords.json +331 -0
  209. data/vendor/kreuzberg/stopwords/pt_stopwords.json +562 -0
  210. data/vendor/kreuzberg/stopwords/ro_stopwords.json +436 -0
  211. data/vendor/kreuzberg/stopwords/ru_stopwords.json +561 -0
  212. data/vendor/kreuzberg/stopwords/si_stopwords.json +193 -0
  213. data/vendor/kreuzberg/stopwords/sk_stopwords.json +420 -0
  214. data/vendor/kreuzberg/stopwords/sl_stopwords.json +448 -0
  215. data/vendor/kreuzberg/stopwords/so_stopwords.json +32 -0
  216. data/vendor/kreuzberg/stopwords/st_stopwords.json +33 -0
  217. data/vendor/kreuzberg/stopwords/sv_stopwords.json +420 -0
  218. data/vendor/kreuzberg/stopwords/sw_stopwords.json +76 -0
  219. data/vendor/kreuzberg/stopwords/ta_stopwords.json +129 -0
  220. data/vendor/kreuzberg/stopwords/te_stopwords.json +54 -0
  221. data/vendor/kreuzberg/stopwords/th_stopwords.json +118 -0
  222. data/vendor/kreuzberg/stopwords/tl_stopwords.json +149 -0
  223. data/vendor/kreuzberg/stopwords/tr_stopwords.json +506 -0
  224. data/vendor/kreuzberg/stopwords/uk_stopwords.json +75 -0
  225. data/vendor/kreuzberg/stopwords/ur_stopwords.json +519 -0
  226. data/vendor/kreuzberg/stopwords/vi_stopwords.json +647 -0
  227. data/vendor/kreuzberg/stopwords/yo_stopwords.json +62 -0
  228. data/vendor/kreuzberg/stopwords/zh_stopwords.json +796 -0
  229. data/vendor/kreuzberg/stopwords/zu_stopwords.json +31 -0
  230. data/vendor/kreuzberg/tests/api_tests.rs +966 -0
  231. data/vendor/kreuzberg/tests/archive_integration.rs +543 -0
  232. data/vendor/kreuzberg/tests/batch_orchestration.rs +542 -0
  233. data/vendor/kreuzberg/tests/batch_processing.rs +304 -0
  234. data/vendor/kreuzberg/tests/chunking_offset_demo.rs +92 -0
  235. data/vendor/kreuzberg/tests/concurrency_stress.rs +509 -0
  236. data/vendor/kreuzberg/tests/config_features.rs +580 -0
  237. data/vendor/kreuzberg/tests/config_loading_tests.rs +439 -0
  238. data/vendor/kreuzberg/tests/core_integration.rs +493 -0
  239. data/vendor/kreuzberg/tests/csv_integration.rs +424 -0
  240. data/vendor/kreuzberg/tests/docx_metadata_extraction_test.rs +124 -0
  241. data/vendor/kreuzberg/tests/email_integration.rs +325 -0
  242. data/vendor/kreuzberg/tests/error_handling.rs +393 -0
  243. data/vendor/kreuzberg/tests/format_integration.rs +159 -0
  244. data/vendor/kreuzberg/tests/helpers/mod.rs +142 -0
  245. data/vendor/kreuzberg/tests/image_integration.rs +253 -0
  246. data/vendor/kreuzberg/tests/keywords_integration.rs +479 -0
  247. data/vendor/kreuzberg/tests/keywords_quality.rs +509 -0
  248. data/vendor/kreuzberg/tests/mime_detection.rs +428 -0
  249. data/vendor/kreuzberg/tests/ocr_configuration.rs +510 -0
  250. data/vendor/kreuzberg/tests/ocr_errors.rs +676 -0
  251. data/vendor/kreuzberg/tests/ocr_quality.rs +627 -0
  252. data/vendor/kreuzberg/tests/ocr_stress.rs +469 -0
  253. data/vendor/kreuzberg/tests/pandoc_integration.rs +503 -0
  254. data/vendor/kreuzberg/tests/pdf_integration.rs +43 -0
  255. data/vendor/kreuzberg/tests/pipeline_integration.rs +1412 -0
  256. data/vendor/kreuzberg/tests/plugin_ocr_backend_test.rs +771 -0
  257. data/vendor/kreuzberg/tests/plugin_postprocessor_test.rs +561 -0
  258. data/vendor/kreuzberg/tests/plugin_system.rs +921 -0
  259. data/vendor/kreuzberg/tests/plugin_validator_test.rs +783 -0
  260. data/vendor/kreuzberg/tests/registry_integration_tests.rs +607 -0
  261. data/vendor/kreuzberg/tests/security_validation.rs +404 -0
  262. data/vendor/kreuzberg/tests/stopwords_integration_test.rs +888 -0
  263. data/vendor/kreuzberg/tests/test_fastembed.rs +609 -0
  264. data/vendor/kreuzberg/tests/xlsx_metadata_extraction_test.rs +87 -0
  265. metadata +471 -0
@@ -0,0 +1,398 @@
1
+ //! Application properties extraction from docProps/app.xml
2
+ //!
3
+ //! Extracts format-specific metadata from Office Open XML documents.
4
+
5
+ use crate::error::{KreuzbergError, Result};
6
+ use roxmltree::Node;
7
+ use std::io::Read;
8
+ use zip::ZipArchive;
9
+
10
+ /// Application properties from docProps/app.xml for DOCX
11
+ ///
12
+ /// Contains Word-specific document statistics and metadata.
13
+ #[derive(Debug, Clone, Default, PartialEq)]
14
+ pub struct DocxAppProperties {
15
+ /// Application name (e.g., "Microsoft Office Word")
16
+ pub application: Option<String>,
17
+ /// Application version
18
+ pub app_version: Option<String>,
19
+ /// Template filename
20
+ pub template: Option<String>,
21
+ /// Total editing time in minutes
22
+ pub total_time: Option<i32>,
23
+ /// Number of pages
24
+ pub pages: Option<i32>,
25
+ /// Number of words
26
+ pub words: Option<i32>,
27
+ /// Number of characters (excluding spaces)
28
+ pub characters: Option<i32>,
29
+ /// Number of characters (including spaces)
30
+ pub characters_with_spaces: Option<i32>,
31
+ /// Number of lines
32
+ pub lines: Option<i32>,
33
+ /// Number of paragraphs
34
+ pub paragraphs: Option<i32>,
35
+ /// Company name
36
+ pub company: Option<String>,
37
+ /// Document security level
38
+ pub doc_security: Option<i32>,
39
+ /// Scale crop flag
40
+ pub scale_crop: Option<bool>,
41
+ /// Links up to date flag
42
+ pub links_up_to_date: Option<bool>,
43
+ /// Shared document flag
44
+ pub shared_doc: Option<bool>,
45
+ /// Hyperlinks changed flag
46
+ pub hyperlinks_changed: Option<bool>,
47
+ }
48
+
49
+ /// Application properties from docProps/app.xml for XLSX
50
+ ///
51
+ /// Contains Excel-specific document metadata.
52
+ #[derive(Debug, Clone, Default, PartialEq)]
53
+ pub struct XlsxAppProperties {
54
+ /// Application name (e.g., "Microsoft Excel")
55
+ pub application: Option<String>,
56
+ /// Application version
57
+ pub app_version: Option<String>,
58
+ /// Document security level
59
+ pub doc_security: Option<i32>,
60
+ /// Scale crop flag
61
+ pub scale_crop: Option<bool>,
62
+ /// Links up to date flag
63
+ pub links_up_to_date: Option<bool>,
64
+ /// Shared document flag
65
+ pub shared_doc: Option<bool>,
66
+ /// Hyperlinks changed flag
67
+ pub hyperlinks_changed: Option<bool>,
68
+ /// Company name
69
+ pub company: Option<String>,
70
+ /// Worksheet names
71
+ pub worksheet_names: Vec<String>,
72
+ }
73
+
74
+ /// Application properties from docProps/app.xml for PPTX
75
+ ///
76
+ /// Contains PowerPoint-specific document metadata.
77
+ #[derive(Debug, Clone, Default, PartialEq)]
78
+ pub struct PptxAppProperties {
79
+ /// Application name (e.g., "Microsoft Office PowerPoint")
80
+ pub application: Option<String>,
81
+ /// Application version
82
+ pub app_version: Option<String>,
83
+ /// Total editing time in minutes
84
+ pub total_time: Option<i32>,
85
+ /// Company name
86
+ pub company: Option<String>,
87
+ /// Document security level
88
+ pub doc_security: Option<i32>,
89
+ /// Scale crop flag
90
+ pub scale_crop: Option<bool>,
91
+ /// Links up to date flag
92
+ pub links_up_to_date: Option<bool>,
93
+ /// Shared document flag
94
+ pub shared_doc: Option<bool>,
95
+ /// Hyperlinks changed flag
96
+ pub hyperlinks_changed: Option<bool>,
97
+ /// Number of slides
98
+ pub slides: Option<i32>,
99
+ /// Number of notes
100
+ pub notes: Option<i32>,
101
+ /// Number of hidden slides
102
+ pub hidden_slides: Option<i32>,
103
+ /// Number of multimedia clips
104
+ pub multimedia_clips: Option<i32>,
105
+ /// Presentation format (e.g., "Widescreen", "Standard")
106
+ pub presentation_format: Option<String>,
107
+ /// Slide titles
108
+ pub slide_titles: Vec<String>,
109
+ }
110
+
111
+ /// Extract DOCX application properties from an Office Open XML document
112
+ ///
113
+ /// Parses `docProps/app.xml` and extracts Word-specific metadata.
114
+ pub fn extract_docx_app_properties<R: Read + std::io::Seek>(archive: &mut ZipArchive<R>) -> Result<DocxAppProperties> {
115
+ let mut xml_content = String::new();
116
+
117
+ match archive.by_name("docProps/app.xml") {
118
+ Ok(mut file) => {
119
+ file.read_to_string(&mut xml_content)
120
+ .map_err(|e| KreuzbergError::parsing(format!("Failed to read app.xml: {}", e)))?;
121
+ }
122
+ Err(_) => {
123
+ return Ok(DocxAppProperties::default());
124
+ }
125
+ }
126
+
127
+ let doc = roxmltree::Document::parse(&xml_content)
128
+ .map_err(|e| KreuzbergError::parsing(format!("Failed to parse app.xml: {}", e)))?;
129
+
130
+ let root = doc.root_element();
131
+
132
+ Ok(DocxAppProperties {
133
+ application: super::parse_xml_text(root, "Application"),
134
+ app_version: super::parse_xml_text(root, "AppVersion"),
135
+ template: super::parse_xml_text(root, "Template"),
136
+ total_time: super::parse_xml_int(root, "TotalTime"),
137
+ pages: super::parse_xml_int(root, "Pages"),
138
+ words: super::parse_xml_int(root, "Words"),
139
+ characters: super::parse_xml_int(root, "Characters"),
140
+ characters_with_spaces: super::parse_xml_int(root, "CharactersWithSpaces"),
141
+ lines: super::parse_xml_int(root, "Lines"),
142
+ paragraphs: super::parse_xml_int(root, "Paragraphs"),
143
+ company: super::parse_xml_text(root, "Company"),
144
+ doc_security: super::parse_xml_int(root, "DocSecurity"),
145
+ scale_crop: super::parse_xml_bool(root, "ScaleCrop"),
146
+ links_up_to_date: super::parse_xml_bool(root, "LinksUpToDate"),
147
+ shared_doc: super::parse_xml_bool(root, "SharedDoc"),
148
+ hyperlinks_changed: super::parse_xml_bool(root, "HyperlinksChanged"),
149
+ })
150
+ }
151
+
152
+ /// Extract XLSX application properties from an Office Open XML document
153
+ ///
154
+ /// Parses `docProps/app.xml` and extracts Excel-specific metadata including worksheet names.
155
+ pub fn extract_xlsx_app_properties<R: Read + std::io::Seek>(archive: &mut ZipArchive<R>) -> Result<XlsxAppProperties> {
156
+ let mut xml_content = String::new();
157
+
158
+ match archive.by_name("docProps/app.xml") {
159
+ Ok(mut file) => {
160
+ file.read_to_string(&mut xml_content)
161
+ .map_err(|e| KreuzbergError::parsing(format!("Failed to read app.xml: {}", e)))?;
162
+ }
163
+ Err(_) => {
164
+ return Ok(XlsxAppProperties::default());
165
+ }
166
+ }
167
+
168
+ let doc = roxmltree::Document::parse(&xml_content)
169
+ .map_err(|e| KreuzbergError::parsing(format!("Failed to parse app.xml: {}", e)))?;
170
+
171
+ let root = doc.root_element();
172
+
173
+ let worksheet_names = extract_titles_of_parts(root);
174
+
175
+ Ok(XlsxAppProperties {
176
+ application: super::parse_xml_text(root, "Application"),
177
+ app_version: super::parse_xml_text(root, "AppVersion"),
178
+ doc_security: super::parse_xml_int(root, "DocSecurity"),
179
+ scale_crop: super::parse_xml_bool(root, "ScaleCrop"),
180
+ links_up_to_date: super::parse_xml_bool(root, "LinksUpToDate"),
181
+ shared_doc: super::parse_xml_bool(root, "SharedDoc"),
182
+ hyperlinks_changed: super::parse_xml_bool(root, "HyperlinksChanged"),
183
+ company: super::parse_xml_text(root, "Company"),
184
+ worksheet_names,
185
+ })
186
+ }
187
+
188
+ /// Extract PPTX application properties from an Office Open XML document
189
+ ///
190
+ /// Parses `docProps/app.xml` and extracts PowerPoint-specific metadata including slide information.
191
+ pub fn extract_pptx_app_properties<R: Read + std::io::Seek>(archive: &mut ZipArchive<R>) -> Result<PptxAppProperties> {
192
+ let mut xml_content = String::new();
193
+
194
+ match archive.by_name("docProps/app.xml") {
195
+ Ok(mut file) => {
196
+ file.read_to_string(&mut xml_content)
197
+ .map_err(|e| KreuzbergError::parsing(format!("Failed to read app.xml: {}", e)))?;
198
+ }
199
+ Err(_) => {
200
+ return Ok(PptxAppProperties::default());
201
+ }
202
+ }
203
+
204
+ let doc = roxmltree::Document::parse(&xml_content)
205
+ .map_err(|e| KreuzbergError::parsing(format!("Failed to parse app.xml: {}", e)))?;
206
+
207
+ let root = doc.root_element();
208
+
209
+ let slide_titles = extract_titles_of_parts(root);
210
+
211
+ let presentation_format = super::parse_xml_text(root, "PresentationFormat");
212
+
213
+ Ok(PptxAppProperties {
214
+ application: super::parse_xml_text(root, "Application"),
215
+ app_version: super::parse_xml_text(root, "AppVersion"),
216
+ total_time: super::parse_xml_int(root, "TotalTime"),
217
+ company: super::parse_xml_text(root, "Company"),
218
+ doc_security: super::parse_xml_int(root, "DocSecurity"),
219
+ scale_crop: super::parse_xml_bool(root, "ScaleCrop"),
220
+ links_up_to_date: super::parse_xml_bool(root, "LinksUpToDate"),
221
+ shared_doc: super::parse_xml_bool(root, "SharedDoc"),
222
+ hyperlinks_changed: super::parse_xml_bool(root, "HyperlinksChanged"),
223
+ slides: super::parse_xml_int(root, "Slides"),
224
+ notes: super::parse_xml_int(root, "Notes"),
225
+ hidden_slides: super::parse_xml_int(root, "HiddenSlides"),
226
+ multimedia_clips: super::parse_xml_int(root, "MMClips"),
227
+ presentation_format,
228
+ slide_titles,
229
+ })
230
+ }
231
+
232
+ /// Extract titles from TitlesOfParts vt:vector element
233
+ ///
234
+ /// Handles the vt:vector/vt:lpstr structure used for worksheet/slide names.
235
+ fn extract_titles_of_parts(root: Node) -> Vec<String> {
236
+ let mut titles = Vec::new();
237
+
238
+ if let Some(titles_node) = root.descendants().find(|n| n.has_tag_name("TitlesOfParts"))
239
+ && let Some(vector_node) = titles_node.descendants().find(|n| n.has_tag_name("vector"))
240
+ {
241
+ for lpstr_node in vector_node.descendants().filter(|n| n.has_tag_name("lpstr")) {
242
+ if let Some(text) = lpstr_node.text() {
243
+ let text = text.trim();
244
+ if !text.is_empty() {
245
+ titles.push(text.to_string());
246
+ }
247
+ }
248
+ }
249
+ }
250
+
251
+ titles
252
+ }
253
+
254
+ #[cfg(test)]
255
+ mod tests {
256
+ use super::*;
257
+ use std::io::{Cursor, Write};
258
+
259
+ fn create_test_zip_with_app_xml(app_xml: &str) -> ZipArchive<Cursor<Vec<u8>>> {
260
+ let buffer = Vec::new();
261
+ let cursor = Cursor::new(buffer);
262
+ let mut zip = zip::ZipWriter::new(cursor);
263
+
264
+ let options = zip::write::FileOptions::<()>::default().compression_method(zip::CompressionMethod::Stored);
265
+
266
+ zip.start_file("docProps/app.xml", options).unwrap();
267
+ zip.write_all(app_xml.as_bytes()).unwrap();
268
+
269
+ let cursor = zip.finish().unwrap();
270
+ ZipArchive::new(cursor).unwrap()
271
+ }
272
+
273
+ #[test]
274
+ fn test_extract_docx_app_properties() {
275
+ let app_xml = r#"<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
276
+ <Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties">
277
+ <Application>Microsoft Office Word</Application>
278
+ <AppVersion>16.0000</AppVersion>
279
+ <TotalTime>120</TotalTime>
280
+ <Pages>5</Pages>
281
+ <Words>1000</Words>
282
+ <Characters>5500</Characters>
283
+ <CharactersWithSpaces>6500</CharactersWithSpaces>
284
+ <Lines>100</Lines>
285
+ <Paragraphs>50</Paragraphs>
286
+ <Company>Acme Corp</Company>
287
+ <DocSecurity>0</DocSecurity>
288
+ <ScaleCrop>false</ScaleCrop>
289
+ </Properties>"#;
290
+
291
+ let mut archive = create_test_zip_with_app_xml(app_xml);
292
+ let props = extract_docx_app_properties(&mut archive).unwrap();
293
+
294
+ assert_eq!(props.application, Some("Microsoft Office Word".to_string()));
295
+ assert_eq!(props.app_version, Some("16.0000".to_string()));
296
+ assert_eq!(props.total_time, Some(120));
297
+ assert_eq!(props.pages, Some(5));
298
+ assert_eq!(props.words, Some(1000));
299
+ assert_eq!(props.characters, Some(5500));
300
+ assert_eq!(props.characters_with_spaces, Some(6500));
301
+ assert_eq!(props.lines, Some(100));
302
+ assert_eq!(props.paragraphs, Some(50));
303
+ assert_eq!(props.company, Some("Acme Corp".to_string()));
304
+ assert_eq!(props.doc_security, Some(0));
305
+ assert_eq!(props.scale_crop, Some(false));
306
+ }
307
+
308
+ #[test]
309
+ fn test_extract_xlsx_app_properties_with_worksheets() {
310
+ let app_xml = r#"<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
311
+ <Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties"
312
+ xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes">
313
+ <Application>Microsoft Excel</Application>
314
+ <AppVersion>16.0300</AppVersion>
315
+ <Company>Test Company</Company>
316
+ <TitlesOfParts>
317
+ <vt:vector size="3" baseType="lpstr">
318
+ <vt:lpstr>Sheet1</vt:lpstr>
319
+ <vt:lpstr>Sheet2</vt:lpstr>
320
+ <vt:lpstr>Sheet3</vt:lpstr>
321
+ </vt:vector>
322
+ </TitlesOfParts>
323
+ </Properties>"#;
324
+
325
+ let mut archive = create_test_zip_with_app_xml(app_xml);
326
+ let props = extract_xlsx_app_properties(&mut archive).unwrap();
327
+
328
+ assert_eq!(props.application, Some("Microsoft Excel".to_string()));
329
+ assert_eq!(props.app_version, Some("16.0300".to_string()));
330
+ assert_eq!(props.company, Some("Test Company".to_string()));
331
+ assert_eq!(props.worksheet_names, vec!["Sheet1", "Sheet2", "Sheet3"]);
332
+ }
333
+
334
+ #[test]
335
+ fn test_extract_pptx_app_properties() {
336
+ let app_xml = r#"<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
337
+ <Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties"
338
+ xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes">
339
+ <Application>Microsoft Office PowerPoint</Application>
340
+ <AppVersion>16.0000</AppVersion>
341
+ <TotalTime>45</TotalTime>
342
+ <Slides>10</Slides>
343
+ <Notes>5</Notes>
344
+ <HiddenSlides>2</HiddenSlides>
345
+ <MMClips>3</MMClips>
346
+ <PresentationFormat>Widescreen</PresentationFormat>
347
+ <TitlesOfParts>
348
+ <vt:vector size="2" baseType="lpstr">
349
+ <vt:lpstr>Title Slide</vt:lpstr>
350
+ <vt:lpstr>Agenda</vt:lpstr>
351
+ </vt:vector>
352
+ </TitlesOfParts>
353
+ </Properties>"#;
354
+
355
+ let mut archive = create_test_zip_with_app_xml(app_xml);
356
+ let props = extract_pptx_app_properties(&mut archive).unwrap();
357
+
358
+ assert_eq!(props.application, Some("Microsoft Office PowerPoint".to_string()));
359
+ assert_eq!(props.slides, Some(10));
360
+ assert_eq!(props.notes, Some(5));
361
+ assert_eq!(props.hidden_slides, Some(2));
362
+ assert_eq!(props.multimedia_clips, Some(3));
363
+ assert_eq!(props.presentation_format, Some("Widescreen".to_string()));
364
+ assert_eq!(props.slide_titles, vec!["Title Slide", "Agenda"]);
365
+ }
366
+
367
+ #[test]
368
+ fn test_extract_app_properties_missing_file() {
369
+ let buffer = Vec::new();
370
+ let cursor = Cursor::new(buffer);
371
+ let zip = zip::ZipWriter::new(cursor);
372
+ let cursor = zip.finish().unwrap();
373
+ let mut archive = ZipArchive::new(cursor).unwrap();
374
+
375
+ let docx = extract_docx_app_properties(&mut archive).unwrap();
376
+ assert_eq!(docx, DocxAppProperties::default());
377
+
378
+ let buffer = Vec::new();
379
+ let cursor = Cursor::new(buffer);
380
+ let zip = zip::ZipWriter::new(cursor);
381
+ let cursor = zip.finish().unwrap();
382
+ let mut archive = ZipArchive::new(cursor).unwrap();
383
+
384
+ let xlsx = extract_xlsx_app_properties(&mut archive).unwrap();
385
+ assert_eq!(xlsx, XlsxAppProperties::default());
386
+ }
387
+
388
+ #[test]
389
+ fn test_extract_titles_of_parts_empty() {
390
+ let xml = r#"<Properties xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes">
391
+ <TitlesOfParts><vt:vector size="0" baseType="lpstr"></vt:vector></TitlesOfParts>
392
+ </Properties>"#;
393
+
394
+ let doc = roxmltree::Document::parse(xml).unwrap();
395
+ let titles = extract_titles_of_parts(doc.root_element());
396
+ assert_eq!(titles, Vec::<String>::new());
397
+ }
398
+ }
@@ -0,0 +1,247 @@
1
+ //! Core properties extraction from docProps/core.xml
2
+ //!
3
+ //! Extracts Dublin Core metadata from Office Open XML documents.
4
+
5
+ use crate::error::{KreuzbergError, Result};
6
+ use std::io::Read;
7
+ use zip::ZipArchive;
8
+
9
+ /// Dublin Core metadata from docProps/core.xml
10
+ ///
11
+ /// Contains standard metadata fields defined by the Dublin Core standard
12
+ /// and Office-specific extensions.
13
+ #[derive(Debug, Clone, Default, PartialEq)]
14
+ pub struct CoreProperties {
15
+ /// Document title
16
+ pub title: Option<String>,
17
+ /// Document subject/topic
18
+ pub subject: Option<String>,
19
+ /// Document creator/author
20
+ pub creator: Option<String>,
21
+ /// Keywords or tags
22
+ pub keywords: Option<String>,
23
+ /// Document description/abstract
24
+ pub description: Option<String>,
25
+ /// User who last modified the document
26
+ pub last_modified_by: Option<String>,
27
+ /// Revision number
28
+ pub revision: Option<String>,
29
+ /// Creation timestamp (ISO 8601)
30
+ pub created: Option<String>,
31
+ /// Last modification timestamp (ISO 8601)
32
+ pub modified: Option<String>,
33
+ /// Document category
34
+ pub category: Option<String>,
35
+ /// Content status (Draft, Final, etc.)
36
+ pub content_status: Option<String>,
37
+ /// Document language
38
+ pub language: Option<String>,
39
+ /// Unique identifier
40
+ pub identifier: Option<String>,
41
+ /// Document version
42
+ pub version: Option<String>,
43
+ /// Last print timestamp (ISO 8601)
44
+ pub last_printed: Option<String>,
45
+ }
46
+
47
+ /// Extract core properties from an Office Open XML document
48
+ ///
49
+ /// Parses `docProps/core.xml` from the ZIP archive and extracts Dublin Core metadata.
50
+ ///
51
+ /// # Arguments
52
+ ///
53
+ /// * `archive` - ZIP archive containing the Office document
54
+ ///
55
+ /// # Returns
56
+ ///
57
+ /// Returns `CoreProperties` with extracted metadata. Fields that are not present
58
+ /// in the document will be `None`.
59
+ ///
60
+ /// # Errors
61
+ ///
62
+ /// Returns an error if:
63
+ /// - The ZIP archive cannot be read
64
+ /// - The core.xml file is malformed
65
+ /// - XML parsing fails
66
+ ///
67
+ /// # Example
68
+ ///
69
+ /// ```no_run
70
+ /// use kreuzberg::extraction::office_metadata::extract_core_properties;
71
+ /// use std::fs::File;
72
+ /// use zip::ZipArchive;
73
+ ///
74
+ /// let file = File::open("document.docx")?;
75
+ /// let mut archive = ZipArchive::new(file)?;
76
+ /// let core = extract_core_properties(&mut archive)?;
77
+ ///
78
+ /// println!("Title: {:?}", core.title);
79
+ /// println!("Creator: {:?}", core.creator);
80
+ /// println!("Created: {:?}", core.created);
81
+ /// # Ok::<(), Box<dyn std::error::Error>>(())
82
+ /// ```
83
+ pub fn extract_core_properties<R: Read + std::io::Seek>(archive: &mut ZipArchive<R>) -> Result<CoreProperties> {
84
+ let mut xml_content = String::new();
85
+
86
+ match archive.by_name("docProps/core.xml") {
87
+ Ok(mut file) => {
88
+ file.read_to_string(&mut xml_content)
89
+ .map_err(|e| KreuzbergError::parsing(format!("Failed to read core.xml: {}", e)))?;
90
+ }
91
+ Err(_) => {
92
+ return Ok(CoreProperties::default());
93
+ }
94
+ }
95
+
96
+ let doc = roxmltree::Document::parse(&xml_content)
97
+ .map_err(|e| KreuzbergError::parsing(format!("Failed to parse core.xml: {}", e)))?;
98
+
99
+ let root = doc.root_element();
100
+
101
+ let title = super::parse_xml_text(root, "title");
102
+ let subject = super::parse_xml_text(root, "subject");
103
+ let creator = super::parse_xml_text(root, "creator");
104
+ let description = super::parse_xml_text(root, "description");
105
+ let language = super::parse_xml_text(root, "language");
106
+ let identifier = super::parse_xml_text(root, "identifier");
107
+
108
+ let keywords = super::parse_xml_text(root, "keywords");
109
+ let last_modified_by = super::parse_xml_text(root, "lastModifiedBy");
110
+ let revision = super::parse_xml_text(root, "revision");
111
+ let category = super::parse_xml_text(root, "category");
112
+ let content_status = super::parse_xml_text(root, "contentStatus");
113
+ let version = super::parse_xml_text(root, "version");
114
+
115
+ let created = super::parse_xml_text(root, "created");
116
+ let modified = super::parse_xml_text(root, "modified");
117
+ let last_printed = super::parse_xml_text(root, "lastPrinted");
118
+
119
+ Ok(CoreProperties {
120
+ title,
121
+ subject,
122
+ creator,
123
+ keywords,
124
+ description,
125
+ last_modified_by,
126
+ revision,
127
+ created,
128
+ modified,
129
+ category,
130
+ content_status,
131
+ language,
132
+ identifier,
133
+ version,
134
+ last_printed,
135
+ })
136
+ }
137
+
138
+ #[cfg(test)]
139
+ mod tests {
140
+ use super::*;
141
+ use std::io::{Cursor, Write};
142
+
143
+ fn create_test_zip_with_core_xml(core_xml: &str) -> ZipArchive<Cursor<Vec<u8>>> {
144
+ let buffer = Vec::new();
145
+ let cursor = Cursor::new(buffer);
146
+ let mut zip = zip::ZipWriter::new(cursor);
147
+
148
+ let options = zip::write::FileOptions::<()>::default().compression_method(zip::CompressionMethod::Stored);
149
+
150
+ zip.start_file("docProps/core.xml", options).unwrap();
151
+ zip.write_all(core_xml.as_bytes()).unwrap();
152
+
153
+ let cursor = zip.finish().unwrap();
154
+ ZipArchive::new(cursor).unwrap()
155
+ }
156
+
157
+ #[test]
158
+ fn test_extract_core_properties_full() {
159
+ let core_xml = r#"<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
160
+ <cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties"
161
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
162
+ xmlns:dcterms="http://purl.org/dc/terms/"
163
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
164
+ <dc:title>Test Document</dc:title>
165
+ <dc:subject>Testing</dc:subject>
166
+ <dc:creator>John Doe</dc:creator>
167
+ <cp:keywords>test, metadata</cp:keywords>
168
+ <dc:description>A test document</dc:description>
169
+ <cp:lastModifiedBy>Jane Doe</cp:lastModifiedBy>
170
+ <cp:revision>5</cp:revision>
171
+ <dcterms:created xsi:type="dcterms:W3CDTF">2024-01-01T10:00:00Z</dcterms:created>
172
+ <dcterms:modified xsi:type="dcterms:W3CDTF">2024-01-02T15:30:00Z</dcterms:modified>
173
+ <cp:category>Documents</cp:category>
174
+ <cp:contentStatus>Final</cp:contentStatus>
175
+ <dc:language>en-US</dc:language>
176
+ </cp:coreProperties>"#;
177
+
178
+ let mut archive = create_test_zip_with_core_xml(core_xml);
179
+ let props = extract_core_properties(&mut archive).unwrap();
180
+
181
+ assert_eq!(props.title, Some("Test Document".to_string()));
182
+ assert_eq!(props.subject, Some("Testing".to_string()));
183
+ assert_eq!(props.creator, Some("John Doe".to_string()));
184
+ assert_eq!(props.keywords, Some("test, metadata".to_string()));
185
+ assert_eq!(props.description, Some("A test document".to_string()));
186
+ assert_eq!(props.last_modified_by, Some("Jane Doe".to_string()));
187
+ assert_eq!(props.revision, Some("5".to_string()));
188
+ assert_eq!(props.created, Some("2024-01-01T10:00:00Z".to_string()));
189
+ assert_eq!(props.modified, Some("2024-01-02T15:30:00Z".to_string()));
190
+ assert_eq!(props.category, Some("Documents".to_string()));
191
+ assert_eq!(props.content_status, Some("Final".to_string()));
192
+ assert_eq!(props.language, Some("en-US".to_string()));
193
+ }
194
+
195
+ #[test]
196
+ fn test_extract_core_properties_minimal() {
197
+ let core_xml = r#"<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
198
+ <cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties"
199
+ xmlns:dc="http://purl.org/dc/elements/1.1/">
200
+ <dc:creator>Alice</dc:creator>
201
+ </cp:coreProperties>"#;
202
+
203
+ let mut archive = create_test_zip_with_core_xml(core_xml);
204
+ let props = extract_core_properties(&mut archive).unwrap();
205
+
206
+ assert_eq!(props.creator, Some("Alice".to_string()));
207
+ assert_eq!(props.title, None);
208
+ assert_eq!(props.keywords, None);
209
+ }
210
+
211
+ #[test]
212
+ fn test_extract_core_properties_empty_elements() {
213
+ let core_xml = r#"<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
214
+ <cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties"
215
+ xmlns:dc="http://purl.org/dc/elements/1.1/">
216
+ <dc:title></dc:title>
217
+ <dc:creator>Bob</dc:creator>
218
+ </cp:coreProperties>"#;
219
+
220
+ let mut archive = create_test_zip_with_core_xml(core_xml);
221
+ let props = extract_core_properties(&mut archive).unwrap();
222
+
223
+ assert_eq!(props.title, None);
224
+ assert_eq!(props.creator, Some("Bob".to_string()));
225
+ }
226
+
227
+ #[test]
228
+ fn test_extract_core_properties_missing_file() {
229
+ let buffer = Vec::new();
230
+ let cursor = Cursor::new(buffer);
231
+ let zip = zip::ZipWriter::new(cursor);
232
+ let cursor = zip.finish().unwrap();
233
+ let mut archive = ZipArchive::new(cursor).unwrap();
234
+
235
+ let props = extract_core_properties(&mut archive).unwrap();
236
+ assert_eq!(props, CoreProperties::default());
237
+ }
238
+
239
+ #[test]
240
+ fn test_extract_core_properties_malformed_xml() {
241
+ let core_xml = "not valid xml <";
242
+ let mut archive = create_test_zip_with_core_xml(core_xml);
243
+
244
+ let result = extract_core_properties(&mut archive);
245
+ assert!(result.is_err());
246
+ }
247
+ }