kreuzberg 4.0.0.pre.rc.29 → 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.
- checksums.yaml +4 -4
- data/.gitignore +0 -6
- data/.rubocop.yaml +534 -1
- data/Gemfile +2 -1
- data/Gemfile.lock +28 -116
- data/README.md +269 -629
- data/Rakefile +0 -9
- data/Steepfile +4 -8
- data/examples/async_patterns.rb +58 -1
- data/ext/kreuzberg_rb/extconf.rb +5 -35
- data/ext/kreuzberg_rb/native/Cargo.toml +16 -55
- data/ext/kreuzberg_rb/native/build.rs +14 -12
- data/ext/kreuzberg_rb/native/include/ieeefp.h +1 -1
- data/ext/kreuzberg_rb/native/include/msvc_compat/strings.h +1 -1
- data/ext/kreuzberg_rb/native/include/strings.h +2 -2
- data/ext/kreuzberg_rb/native/include/unistd.h +1 -1
- data/ext/kreuzberg_rb/native/src/lib.rs +34 -897
- data/extconf.rb +6 -38
- data/kreuzberg.gemspec +20 -114
- data/lib/kreuzberg/api_proxy.rb +18 -2
- data/lib/kreuzberg/cache_api.rb +0 -22
- data/lib/kreuzberg/cli.rb +10 -2
- data/lib/kreuzberg/cli_proxy.rb +10 -0
- data/lib/kreuzberg/config.rb +22 -274
- data/lib/kreuzberg/errors.rb +7 -73
- data/lib/kreuzberg/extraction_api.rb +8 -237
- data/lib/kreuzberg/mcp_proxy.rb +11 -2
- data/lib/kreuzberg/ocr_backend_protocol.rb +73 -0
- data/lib/kreuzberg/post_processor_protocol.rb +71 -0
- data/lib/kreuzberg/result.rb +33 -151
- data/lib/kreuzberg/setup_lib_path.rb +2 -22
- data/lib/kreuzberg/validator_protocol.rb +73 -0
- data/lib/kreuzberg/version.rb +1 -1
- data/lib/kreuzberg.rb +13 -27
- data/pkg/kreuzberg-4.0.0.rc1.gem +0 -0
- data/sig/kreuzberg.rbs +12 -105
- data/spec/binding/cache_spec.rb +22 -22
- data/spec/binding/cli_proxy_spec.rb +4 -2
- data/spec/binding/cli_spec.rb +11 -12
- data/spec/binding/config_spec.rb +0 -74
- data/spec/binding/config_validation_spec.rb +6 -100
- data/spec/binding/error_handling_spec.rb +97 -283
- data/spec/binding/plugins/ocr_backend_spec.rb +8 -8
- data/spec/binding/plugins/postprocessor_spec.rb +11 -11
- data/spec/binding/plugins/validator_spec.rb +13 -12
- data/spec/examples.txt +104 -0
- data/spec/fixtures/config.toml +1 -0
- data/spec/fixtures/config.yaml +1 -0
- data/spec/fixtures/invalid_config.toml +1 -0
- data/spec/smoke/package_spec.rb +3 -2
- data/spec/spec_helper.rb +3 -1
- data/vendor/kreuzberg/Cargo.toml +67 -192
- data/vendor/kreuzberg/README.md +9 -97
- data/vendor/kreuzberg/build.rs +194 -516
- data/vendor/kreuzberg/src/api/handlers.rs +9 -130
- data/vendor/kreuzberg/src/api/mod.rs +3 -18
- data/vendor/kreuzberg/src/api/server.rs +71 -236
- data/vendor/kreuzberg/src/api/types.rs +7 -43
- data/vendor/kreuzberg/src/bin/profile_extract.rs +455 -0
- data/vendor/kreuzberg/src/cache/mod.rs +3 -27
- data/vendor/kreuzberg/src/chunking/mod.rs +79 -1705
- data/vendor/kreuzberg/src/core/batch_mode.rs +0 -60
- data/vendor/kreuzberg/src/core/config.rs +23 -905
- data/vendor/kreuzberg/src/core/extractor.rs +106 -403
- data/vendor/kreuzberg/src/core/io.rs +2 -4
- data/vendor/kreuzberg/src/core/mime.rs +12 -2
- data/vendor/kreuzberg/src/core/mod.rs +3 -22
- data/vendor/kreuzberg/src/core/pipeline.rs +78 -395
- data/vendor/kreuzberg/src/embeddings.rs +21 -169
- data/vendor/kreuzberg/src/error.rs +2 -2
- data/vendor/kreuzberg/src/extraction/archive.rs +31 -36
- data/vendor/kreuzberg/src/extraction/docx.rs +1 -365
- data/vendor/kreuzberg/src/extraction/email.rs +11 -12
- data/vendor/kreuzberg/src/extraction/excel.rs +129 -138
- data/vendor/kreuzberg/src/extraction/html.rs +170 -1447
- data/vendor/kreuzberg/src/extraction/image.rs +14 -138
- data/vendor/kreuzberg/src/extraction/libreoffice.rs +3 -13
- data/vendor/kreuzberg/src/extraction/mod.rs +5 -21
- data/vendor/kreuzberg/src/extraction/office_metadata/mod.rs +0 -2
- data/vendor/kreuzberg/src/extraction/pandoc/batch.rs +275 -0
- data/vendor/kreuzberg/src/extraction/pandoc/mime_types.rs +178 -0
- data/vendor/kreuzberg/src/extraction/pandoc/mod.rs +491 -0
- data/vendor/kreuzberg/src/extraction/pandoc/server.rs +496 -0
- data/vendor/kreuzberg/src/extraction/pandoc/subprocess.rs +1188 -0
- data/vendor/kreuzberg/src/extraction/pandoc/version.rs +162 -0
- data/vendor/kreuzberg/src/extraction/pptx.rs +94 -196
- data/vendor/kreuzberg/src/extraction/structured.rs +4 -5
- data/vendor/kreuzberg/src/extraction/table.rs +1 -2
- data/vendor/kreuzberg/src/extraction/text.rs +10 -18
- data/vendor/kreuzberg/src/extractors/archive.rs +0 -22
- data/vendor/kreuzberg/src/extractors/docx.rs +148 -69
- data/vendor/kreuzberg/src/extractors/email.rs +9 -37
- data/vendor/kreuzberg/src/extractors/excel.rs +40 -81
- data/vendor/kreuzberg/src/extractors/html.rs +173 -182
- data/vendor/kreuzberg/src/extractors/image.rs +8 -32
- data/vendor/kreuzberg/src/extractors/mod.rs +10 -171
- data/vendor/kreuzberg/src/extractors/pandoc.rs +201 -0
- data/vendor/kreuzberg/src/extractors/pdf.rs +64 -329
- data/vendor/kreuzberg/src/extractors/pptx.rs +34 -79
- data/vendor/kreuzberg/src/extractors/structured.rs +0 -16
- data/vendor/kreuzberg/src/extractors/text.rs +7 -30
- data/vendor/kreuzberg/src/extractors/xml.rs +8 -27
- data/vendor/kreuzberg/src/keywords/processor.rs +1 -9
- data/vendor/kreuzberg/src/keywords/rake.rs +1 -0
- data/vendor/kreuzberg/src/language_detection/mod.rs +51 -94
- data/vendor/kreuzberg/src/lib.rs +5 -17
- data/vendor/kreuzberg/src/mcp/mod.rs +1 -4
- data/vendor/kreuzberg/src/mcp/server.rs +21 -145
- data/vendor/kreuzberg/src/ocr/mod.rs +0 -2
- data/vendor/kreuzberg/src/ocr/processor.rs +8 -19
- data/vendor/kreuzberg/src/ocr/tesseract_backend.rs +0 -2
- data/vendor/kreuzberg/src/pdf/error.rs +1 -93
- data/vendor/kreuzberg/src/pdf/metadata.rs +100 -263
- data/vendor/kreuzberg/src/pdf/mod.rs +2 -33
- data/vendor/kreuzberg/src/pdf/rendering.rs +12 -12
- data/vendor/kreuzberg/src/pdf/table.rs +64 -61
- data/vendor/kreuzberg/src/pdf/text.rs +24 -416
- data/vendor/kreuzberg/src/plugins/extractor.rs +8 -40
- data/vendor/kreuzberg/src/plugins/mod.rs +0 -3
- data/vendor/kreuzberg/src/plugins/ocr.rs +14 -22
- data/vendor/kreuzberg/src/plugins/processor.rs +1 -10
- data/vendor/kreuzberg/src/plugins/registry.rs +0 -15
- data/vendor/kreuzberg/src/plugins/validator.rs +8 -20
- data/vendor/kreuzberg/src/stopwords/mod.rs +2 -2
- data/vendor/kreuzberg/src/text/mod.rs +0 -8
- data/vendor/kreuzberg/src/text/quality.rs +15 -28
- data/vendor/kreuzberg/src/text/string_utils.rs +10 -22
- data/vendor/kreuzberg/src/text/token_reduction/core.rs +50 -86
- data/vendor/kreuzberg/src/text/token_reduction/filters.rs +16 -37
- data/vendor/kreuzberg/src/text/token_reduction/simd_text.rs +1 -2
- data/vendor/kreuzberg/src/types.rs +67 -907
- data/vendor/kreuzberg/src/utils/mod.rs +0 -14
- data/vendor/kreuzberg/src/utils/quality.rs +3 -12
- data/vendor/kreuzberg/tests/api_tests.rs +0 -506
- data/vendor/kreuzberg/tests/archive_integration.rs +0 -2
- data/vendor/kreuzberg/tests/batch_orchestration.rs +12 -57
- data/vendor/kreuzberg/tests/batch_processing.rs +8 -32
- data/vendor/kreuzberg/tests/chunking_offset_demo.rs +92 -0
- data/vendor/kreuzberg/tests/concurrency_stress.rs +8 -40
- data/vendor/kreuzberg/tests/config_features.rs +1 -33
- data/vendor/kreuzberg/tests/config_loading_tests.rs +39 -16
- data/vendor/kreuzberg/tests/core_integration.rs +9 -35
- data/vendor/kreuzberg/tests/csv_integration.rs +81 -71
- data/vendor/kreuzberg/tests/docx_metadata_extraction_test.rs +25 -23
- data/vendor/kreuzberg/tests/email_integration.rs +1 -3
- data/vendor/kreuzberg/tests/error_handling.rs +34 -43
- data/vendor/kreuzberg/tests/format_integration.rs +1 -7
- data/vendor/kreuzberg/tests/helpers/mod.rs +0 -60
- data/vendor/kreuzberg/tests/image_integration.rs +0 -2
- data/vendor/kreuzberg/tests/mime_detection.rs +16 -17
- data/vendor/kreuzberg/tests/ocr_configuration.rs +0 -4
- data/vendor/kreuzberg/tests/ocr_errors.rs +0 -22
- data/vendor/kreuzberg/tests/ocr_quality.rs +0 -2
- data/vendor/kreuzberg/tests/pandoc_integration.rs +503 -0
- data/vendor/kreuzberg/tests/pdf_integration.rs +0 -2
- data/vendor/kreuzberg/tests/pipeline_integration.rs +2 -36
- data/vendor/kreuzberg/tests/plugin_ocr_backend_test.rs +0 -5
- data/vendor/kreuzberg/tests/plugin_postprocessor_test.rs +1 -17
- data/vendor/kreuzberg/tests/plugin_system.rs +0 -6
- data/vendor/kreuzberg/tests/registry_integration_tests.rs +22 -2
- data/vendor/kreuzberg/tests/security_validation.rs +1 -13
- data/vendor/kreuzberg/tests/test_fastembed.rs +23 -45
- metadata +25 -171
- data/.rubocop.yml +0 -543
- data/ext/kreuzberg_rb/native/.cargo/config.toml +0 -23
- data/ext/kreuzberg_rb/native/Cargo.lock +0 -7619
- data/lib/kreuzberg/error_context.rb +0 -136
- data/lib/kreuzberg/types.rb +0 -170
- data/lib/libpdfium.so +0 -0
- data/spec/binding/async_operations_spec.rb +0 -473
- data/spec/binding/batch_operations_spec.rb +0 -595
- data/spec/binding/batch_spec.rb +0 -359
- data/spec/binding/config_result_spec.rb +0 -377
- data/spec/binding/embeddings_spec.rb +0 -816
- data/spec/binding/error_recovery_spec.rb +0 -488
- data/spec/binding/font_config_spec.rb +0 -220
- data/spec/binding/images_spec.rb +0 -738
- data/spec/binding/keywords_extraction_spec.rb +0 -600
- data/spec/binding/metadata_types_spec.rb +0 -1228
- data/spec/binding/pages_extraction_spec.rb +0 -471
- data/spec/binding/tables_spec.rb +0 -641
- data/spec/unit/config/chunking_config_spec.rb +0 -213
- data/spec/unit/config/embedding_config_spec.rb +0 -343
- data/spec/unit/config/extraction_config_spec.rb +0 -438
- data/spec/unit/config/font_config_spec.rb +0 -285
- data/spec/unit/config/hierarchy_config_spec.rb +0 -314
- data/spec/unit/config/image_extraction_config_spec.rb +0 -209
- data/spec/unit/config/image_preprocessing_config_spec.rb +0 -249
- data/spec/unit/config/keyword_config_spec.rb +0 -229
- data/spec/unit/config/language_detection_config_spec.rb +0 -258
- data/spec/unit/config/ocr_config_spec.rb +0 -171
- data/spec/unit/config/page_config_spec.rb +0 -221
- data/spec/unit/config/pdf_config_spec.rb +0 -267
- data/spec/unit/config/postprocessor_config_spec.rb +0 -290
- data/spec/unit/config/tesseract_config_spec.rb +0 -181
- data/spec/unit/config/token_reduction_config_spec.rb +0 -251
- data/test/metadata_types_test.rb +0 -959
- data/vendor/Cargo.toml +0 -61
- data/vendor/kreuzberg/examples/bench_fixes.rs +0 -71
- data/vendor/kreuzberg/examples/test_pdfium_fork.rs +0 -62
- data/vendor/kreuzberg/src/chunking/processor.rs +0 -219
- data/vendor/kreuzberg/src/core/batch_optimizations.rs +0 -385
- data/vendor/kreuzberg/src/core/config_validation.rs +0 -949
- data/vendor/kreuzberg/src/core/formats.rs +0 -235
- data/vendor/kreuzberg/src/core/server_config.rs +0 -1220
- data/vendor/kreuzberg/src/extraction/capacity.rs +0 -263
- data/vendor/kreuzberg/src/extraction/markdown.rs +0 -216
- data/vendor/kreuzberg/src/extraction/office_metadata/odt_properties.rs +0 -284
- data/vendor/kreuzberg/src/extractors/bibtex.rs +0 -470
- data/vendor/kreuzberg/src/extractors/docbook.rs +0 -504
- data/vendor/kreuzberg/src/extractors/epub.rs +0 -696
- data/vendor/kreuzberg/src/extractors/fictionbook.rs +0 -492
- data/vendor/kreuzberg/src/extractors/jats.rs +0 -1054
- data/vendor/kreuzberg/src/extractors/jupyter.rs +0 -368
- data/vendor/kreuzberg/src/extractors/latex.rs +0 -653
- data/vendor/kreuzberg/src/extractors/markdown.rs +0 -701
- data/vendor/kreuzberg/src/extractors/odt.rs +0 -628
- data/vendor/kreuzberg/src/extractors/opml.rs +0 -635
- data/vendor/kreuzberg/src/extractors/orgmode.rs +0 -529
- data/vendor/kreuzberg/src/extractors/rst.rs +0 -577
- data/vendor/kreuzberg/src/extractors/rtf.rs +0 -809
- data/vendor/kreuzberg/src/extractors/security.rs +0 -484
- data/vendor/kreuzberg/src/extractors/security_tests.rs +0 -367
- data/vendor/kreuzberg/src/extractors/typst.rs +0 -651
- data/vendor/kreuzberg/src/language_detection/processor.rs +0 -218
- data/vendor/kreuzberg/src/ocr/language_registry.rs +0 -520
- data/vendor/kreuzberg/src/panic_context.rs +0 -154
- data/vendor/kreuzberg/src/pdf/bindings.rs +0 -306
- data/vendor/kreuzberg/src/pdf/bundled.rs +0 -408
- data/vendor/kreuzberg/src/pdf/fonts.rs +0 -358
- data/vendor/kreuzberg/src/pdf/hierarchy.rs +0 -903
- data/vendor/kreuzberg/src/text/quality_processor.rs +0 -231
- data/vendor/kreuzberg/src/text/utf8_validation.rs +0 -193
- data/vendor/kreuzberg/src/utils/pool.rs +0 -503
- data/vendor/kreuzberg/src/utils/pool_sizing.rs +0 -364
- data/vendor/kreuzberg/src/utils/string_pool.rs +0 -761
- data/vendor/kreuzberg/tests/api_embed.rs +0 -360
- data/vendor/kreuzberg/tests/api_extract_multipart.rs +0 -52
- data/vendor/kreuzberg/tests/api_large_pdf_extraction.rs +0 -471
- data/vendor/kreuzberg/tests/api_large_pdf_extraction_diagnostics.rs +0 -289
- data/vendor/kreuzberg/tests/batch_pooling_benchmark.rs +0 -154
- data/vendor/kreuzberg/tests/bibtex_parity_test.rs +0 -421
- data/vendor/kreuzberg/tests/config_integration_test.rs +0 -753
- data/vendor/kreuzberg/tests/data/hierarchy_ground_truth.json +0 -294
- data/vendor/kreuzberg/tests/docbook_extractor_tests.rs +0 -500
- data/vendor/kreuzberg/tests/docx_vs_pandoc_comparison.rs +0 -370
- data/vendor/kreuzberg/tests/epub_native_extractor_tests.rs +0 -275
- data/vendor/kreuzberg/tests/fictionbook_extractor_tests.rs +0 -228
- data/vendor/kreuzberg/tests/html_table_test.rs +0 -551
- data/vendor/kreuzberg/tests/instrumentation_test.rs +0 -139
- data/vendor/kreuzberg/tests/jats_extractor_tests.rs +0 -639
- data/vendor/kreuzberg/tests/jupyter_extractor_tests.rs +0 -704
- data/vendor/kreuzberg/tests/latex_extractor_tests.rs +0 -496
- data/vendor/kreuzberg/tests/markdown_extractor_tests.rs +0 -490
- data/vendor/kreuzberg/tests/ocr_language_registry.rs +0 -191
- data/vendor/kreuzberg/tests/odt_extractor_tests.rs +0 -674
- data/vendor/kreuzberg/tests/opml_extractor_tests.rs +0 -616
- data/vendor/kreuzberg/tests/orgmode_extractor_tests.rs +0 -822
- data/vendor/kreuzberg/tests/page_markers.rs +0 -297
- data/vendor/kreuzberg/tests/pdf_hierarchy_detection.rs +0 -301
- data/vendor/kreuzberg/tests/pdf_hierarchy_quality.rs +0 -589
- data/vendor/kreuzberg/tests/pdf_ocr_triggering.rs +0 -301
- data/vendor/kreuzberg/tests/pdf_text_merging.rs +0 -475
- data/vendor/kreuzberg/tests/pdfium_linking.rs +0 -340
- data/vendor/kreuzberg/tests/rst_extractor_tests.rs +0 -694
- data/vendor/kreuzberg/tests/rtf_extractor_tests.rs +0 -775
- data/vendor/kreuzberg/tests/typst_behavioral_tests.rs +0 -1260
- data/vendor/kreuzberg/tests/typst_extractor_tests.rs +0 -648
- data/vendor/kreuzberg-ffi/Cargo.toml +0 -67
- data/vendor/kreuzberg-ffi/README.md +0 -851
- data/vendor/kreuzberg-ffi/benches/result_view_benchmark.rs +0 -227
- data/vendor/kreuzberg-ffi/build.rs +0 -168
- data/vendor/kreuzberg-ffi/cbindgen.toml +0 -37
- data/vendor/kreuzberg-ffi/kreuzberg-ffi.pc.in +0 -12
- data/vendor/kreuzberg-ffi/kreuzberg.h +0 -3012
- data/vendor/kreuzberg-ffi/src/batch_streaming.rs +0 -588
- data/vendor/kreuzberg-ffi/src/config.rs +0 -1341
- data/vendor/kreuzberg-ffi/src/error.rs +0 -901
- data/vendor/kreuzberg-ffi/src/extraction.rs +0 -555
- data/vendor/kreuzberg-ffi/src/helpers.rs +0 -879
- data/vendor/kreuzberg-ffi/src/lib.rs +0 -977
- data/vendor/kreuzberg-ffi/src/memory.rs +0 -493
- data/vendor/kreuzberg-ffi/src/mime.rs +0 -329
- data/vendor/kreuzberg-ffi/src/panic_shield.rs +0 -265
- data/vendor/kreuzberg-ffi/src/plugins/document_extractor.rs +0 -442
- data/vendor/kreuzberg-ffi/src/plugins/mod.rs +0 -14
- data/vendor/kreuzberg-ffi/src/plugins/ocr_backend.rs +0 -628
- data/vendor/kreuzberg-ffi/src/plugins/post_processor.rs +0 -438
- data/vendor/kreuzberg-ffi/src/plugins/validator.rs +0 -329
- data/vendor/kreuzberg-ffi/src/result.rs +0 -510
- data/vendor/kreuzberg-ffi/src/result_pool.rs +0 -639
- data/vendor/kreuzberg-ffi/src/result_view.rs +0 -773
- data/vendor/kreuzberg-ffi/src/string_intern.rs +0 -568
- data/vendor/kreuzberg-ffi/src/types.rs +0 -363
- data/vendor/kreuzberg-ffi/src/util.rs +0 -210
- data/vendor/kreuzberg-ffi/src/validation.rs +0 -848
- data/vendor/kreuzberg-ffi/tests.disabled/README.md +0 -48
- data/vendor/kreuzberg-ffi/tests.disabled/config_loading_tests.rs +0 -299
- data/vendor/kreuzberg-ffi/tests.disabled/config_tests.rs +0 -346
- data/vendor/kreuzberg-ffi/tests.disabled/extractor_tests.rs +0 -232
- data/vendor/kreuzberg-ffi/tests.disabled/plugin_registration_tests.rs +0 -470
- data/vendor/kreuzberg-tesseract/.commitlintrc.json +0 -13
- data/vendor/kreuzberg-tesseract/.crate-ignore +0 -2
- data/vendor/kreuzberg-tesseract/Cargo.lock +0 -2933
- data/vendor/kreuzberg-tesseract/Cargo.toml +0 -57
- data/vendor/kreuzberg-tesseract/LICENSE +0 -22
- data/vendor/kreuzberg-tesseract/README.md +0 -399
- data/vendor/kreuzberg-tesseract/build.rs +0 -1127
- data/vendor/kreuzberg-tesseract/patches/README.md +0 -71
- data/vendor/kreuzberg-tesseract/patches/tesseract.diff +0 -199
- data/vendor/kreuzberg-tesseract/src/api.rs +0 -1371
- data/vendor/kreuzberg-tesseract/src/choice_iterator.rs +0 -77
- data/vendor/kreuzberg-tesseract/src/enums.rs +0 -297
- data/vendor/kreuzberg-tesseract/src/error.rs +0 -81
- data/vendor/kreuzberg-tesseract/src/lib.rs +0 -145
- data/vendor/kreuzberg-tesseract/src/monitor.rs +0 -57
- data/vendor/kreuzberg-tesseract/src/mutable_iterator.rs +0 -197
- data/vendor/kreuzberg-tesseract/src/page_iterator.rs +0 -253
- data/vendor/kreuzberg-tesseract/src/result_iterator.rs +0 -286
- data/vendor/kreuzberg-tesseract/src/result_renderer.rs +0 -183
- data/vendor/kreuzberg-tesseract/tests/integration_test.rs +0 -211
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
//! This module provides:
|
|
4
4
|
//! - Quality processing: clean OCR artifacts, calculate quality scores
|
|
5
5
|
//! - String utilities: safe decoding, mojibake fixing, encoding detection
|
|
6
|
-
//! - Object pooling: reusable pools for batch processing to reduce allocations
|
|
7
6
|
|
|
8
7
|
#[cfg(feature = "quality")]
|
|
9
8
|
pub mod quality;
|
|
@@ -11,21 +10,8 @@ pub mod quality;
|
|
|
11
10
|
#[cfg(feature = "quality")]
|
|
12
11
|
pub mod string_utils;
|
|
13
12
|
|
|
14
|
-
pub mod pool;
|
|
15
|
-
pub mod pool_sizing;
|
|
16
|
-
pub mod string_pool;
|
|
17
|
-
|
|
18
13
|
#[cfg(feature = "quality")]
|
|
19
14
|
pub use quality::{calculate_quality_score, clean_extracted_text, normalize_spaces};
|
|
20
15
|
|
|
21
16
|
#[cfg(feature = "quality")]
|
|
22
17
|
pub use string_utils::{calculate_text_confidence, fix_mojibake, safe_decode};
|
|
23
|
-
|
|
24
|
-
pub use pool::{
|
|
25
|
-
ByteBufferPool, Pool, PoolError, PoolGuard, Recyclable, StringBufferPool, create_byte_buffer_pool,
|
|
26
|
-
create_string_buffer_pool,
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
pub use pool_sizing::{PoolSizeHint, estimate_pool_size};
|
|
30
|
-
|
|
31
|
-
pub use string_pool::{InternedString, intern_language_code, intern_mime_type};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
use crate::text::utf8_validation;
|
|
2
1
|
use ahash::AHashMap;
|
|
3
2
|
use memchr::{memchr, memchr3};
|
|
4
3
|
use once_cell::sync::Lazy;
|
|
@@ -388,11 +387,7 @@ fn clean_repeated_punctuation_ascii(text: &str) -> Option<String> {
|
|
|
388
387
|
}
|
|
389
388
|
}
|
|
390
389
|
|
|
391
|
-
if changed {
|
|
392
|
-
utf8_validation::string_from_utf8(result).ok()
|
|
393
|
-
} else {
|
|
394
|
-
None
|
|
395
|
-
}
|
|
390
|
+
if changed { String::from_utf8(result).ok() } else { None }
|
|
396
391
|
}
|
|
397
392
|
|
|
398
393
|
#[inline]
|
|
@@ -466,7 +461,7 @@ pub(crate) fn normalize_whitespace_ascii(text: &str) -> Option<String> {
|
|
|
466
461
|
}
|
|
467
462
|
}
|
|
468
463
|
|
|
469
|
-
let normalized =
|
|
464
|
+
let normalized = String::from_utf8(result).unwrap_or_else(|_| text.to_string());
|
|
470
465
|
|
|
471
466
|
if changed { Some(normalized) } else { None }
|
|
472
467
|
}
|
|
@@ -584,11 +579,7 @@ pub(crate) fn collapse_scattered_ascii(text: &str) -> Option<String> {
|
|
|
584
579
|
i += 1;
|
|
585
580
|
}
|
|
586
581
|
|
|
587
|
-
if changed {
|
|
588
|
-
utf8_validation::string_from_utf8(result).ok()
|
|
589
|
-
} else {
|
|
590
|
-
None
|
|
591
|
-
}
|
|
582
|
+
if changed { String::from_utf8(result).ok() } else { None }
|
|
592
583
|
}
|
|
593
584
|
|
|
594
585
|
/// Collapse redundant whitespace while preserving paragraph boundaries.
|
|
@@ -964,509 +964,3 @@ async fn test_extract_default_mime_type() {
|
|
|
964
964
|
|| response.status() == StatusCode::INTERNAL_SERVER_ERROR
|
|
965
965
|
);
|
|
966
966
|
}
|
|
967
|
-
|
|
968
|
-
/// Test size limits configuration with custom limits.
|
|
969
|
-
#[tokio::test]
|
|
970
|
-
async fn test_size_limits_custom_limits() {
|
|
971
|
-
use kreuzberg::api::{ApiSizeLimits, create_router_with_limits};
|
|
972
|
-
|
|
973
|
-
let config = ExtractionConfig::default();
|
|
974
|
-
let limits = ApiSizeLimits::from_mb(50, 50);
|
|
975
|
-
let app = create_router_with_limits(config, limits);
|
|
976
|
-
|
|
977
|
-
assert_eq!(limits.max_request_body_bytes, 50 * 1024 * 1024);
|
|
978
|
-
assert_eq!(limits.max_multipart_field_bytes, 50 * 1024 * 1024);
|
|
979
|
-
|
|
980
|
-
let boundary = "----boundary";
|
|
981
|
-
let file_content = "Test";
|
|
982
|
-
|
|
983
|
-
let body_content = format!(
|
|
984
|
-
"--{}\r\n\
|
|
985
|
-
Content-Disposition: form-data; name=\"files\"; filename=\"test.txt\"\r\n\
|
|
986
|
-
Content-Type: text/plain\r\n\
|
|
987
|
-
\r\n\
|
|
988
|
-
{}\r\n\
|
|
989
|
-
--{}--\r\n",
|
|
990
|
-
boundary, file_content, boundary
|
|
991
|
-
);
|
|
992
|
-
|
|
993
|
-
let response = app
|
|
994
|
-
.oneshot(
|
|
995
|
-
Request::builder()
|
|
996
|
-
.method("POST")
|
|
997
|
-
.uri("/extract")
|
|
998
|
-
.header("content-type", format!("multipart/form-data; boundary={}", boundary))
|
|
999
|
-
.body(Body::from(body_content))
|
|
1000
|
-
.unwrap(),
|
|
1001
|
-
)
|
|
1002
|
-
.await
|
|
1003
|
-
.unwrap();
|
|
1004
|
-
|
|
1005
|
-
assert_eq!(response.status(), StatusCode::OK);
|
|
1006
|
-
}
|
|
1007
|
-
|
|
1008
|
-
/// Test size limits with asymmetric limits (different request vs field sizes).
|
|
1009
|
-
#[tokio::test]
|
|
1010
|
-
async fn test_size_limits_asymmetric() {
|
|
1011
|
-
use kreuzberg::api::{ApiSizeLimits, create_router_with_limits};
|
|
1012
|
-
|
|
1013
|
-
let config = ExtractionConfig::default();
|
|
1014
|
-
let limits = ApiSizeLimits::new(100 * 1024 * 1024, 50 * 1024 * 1024);
|
|
1015
|
-
let _app = create_router_with_limits(config, limits);
|
|
1016
|
-
|
|
1017
|
-
assert_eq!(limits.max_request_body_bytes, 100 * 1024 * 1024);
|
|
1018
|
-
assert_eq!(limits.max_multipart_field_bytes, 50 * 1024 * 1024);
|
|
1019
|
-
}
|
|
1020
|
-
|
|
1021
|
-
/// Test default size limits are 100 MB.
|
|
1022
|
-
#[test]
|
|
1023
|
-
fn test_default_size_limits_100mb() {
|
|
1024
|
-
use kreuzberg::api::ApiSizeLimits;
|
|
1025
|
-
|
|
1026
|
-
let limits = ApiSizeLimits::default();
|
|
1027
|
-
|
|
1028
|
-
assert_eq!(limits.max_request_body_bytes, 100 * 1024 * 1024);
|
|
1029
|
-
assert_eq!(limits.max_multipart_field_bytes, 100 * 1024 * 1024);
|
|
1030
|
-
}
|
|
1031
|
-
|
|
1032
|
-
/// Test ApiSizeLimits from_mb convenience method.
|
|
1033
|
-
#[test]
|
|
1034
|
-
fn test_api_size_limits_from_mb() {
|
|
1035
|
-
use kreuzberg::api::ApiSizeLimits;
|
|
1036
|
-
|
|
1037
|
-
let limits = ApiSizeLimits::from_mb(100, 50);
|
|
1038
|
-
assert_eq!(limits.max_request_body_bytes, 100 * 1024 * 1024);
|
|
1039
|
-
assert_eq!(limits.max_multipart_field_bytes, 50 * 1024 * 1024);
|
|
1040
|
-
}
|
|
1041
|
-
|
|
1042
|
-
/// Test ApiSizeLimits new method.
|
|
1043
|
-
#[test]
|
|
1044
|
-
fn test_api_size_limits_new() {
|
|
1045
|
-
use kreuzberg::api::ApiSizeLimits;
|
|
1046
|
-
|
|
1047
|
-
let limits = ApiSizeLimits::new(1_000_000, 500_000);
|
|
1048
|
-
assert_eq!(limits.max_request_body_bytes, 1_000_000);
|
|
1049
|
-
assert_eq!(limits.max_multipart_field_bytes, 500_000);
|
|
1050
|
-
}
|
|
1051
|
-
|
|
1052
|
-
/// Test extracting a file larger than 2MB (issue #248).
|
|
1053
|
-
///
|
|
1054
|
-
/// This test verifies that the API can handle files larger than Axum's old
|
|
1055
|
-
/// default multipart field limit of 2MB. The issue reported files >2MB being
|
|
1056
|
-
/// rejected with HTTP 400, which was due to Axum's default `DefaultBodyLimit`.
|
|
1057
|
-
///
|
|
1058
|
-
/// With the fix, we now explicitly set `DefaultBodyLimit::max()` to match our
|
|
1059
|
-
/// configured size limits (default 10 GB), allowing large file uploads.
|
|
1060
|
-
#[tokio::test]
|
|
1061
|
-
async fn test_extract_file_larger_than_2mb() {
|
|
1062
|
-
let app = create_router(ExtractionConfig::default());
|
|
1063
|
-
|
|
1064
|
-
let boundary = "----boundary";
|
|
1065
|
-
let file_content = "A".repeat(3 * 1024 * 1024);
|
|
1066
|
-
|
|
1067
|
-
let body_content = format!(
|
|
1068
|
-
"--{}\r\n\
|
|
1069
|
-
Content-Disposition: form-data; name=\"files\"; filename=\"large.txt\"\r\n\
|
|
1070
|
-
Content-Type: text/plain\r\n\
|
|
1071
|
-
\r\n\
|
|
1072
|
-
{}\r\n\
|
|
1073
|
-
--{}--\r\n",
|
|
1074
|
-
boundary, file_content, boundary
|
|
1075
|
-
);
|
|
1076
|
-
|
|
1077
|
-
let response = app
|
|
1078
|
-
.oneshot(
|
|
1079
|
-
Request::builder()
|
|
1080
|
-
.method("POST")
|
|
1081
|
-
.uri("/extract")
|
|
1082
|
-
.header("content-type", format!("multipart/form-data; boundary={}", boundary))
|
|
1083
|
-
.body(Body::from(body_content))
|
|
1084
|
-
.unwrap(),
|
|
1085
|
-
)
|
|
1086
|
-
.await
|
|
1087
|
-
.unwrap();
|
|
1088
|
-
|
|
1089
|
-
assert_eq!(
|
|
1090
|
-
response.status(),
|
|
1091
|
-
StatusCode::OK,
|
|
1092
|
-
"3MB file should be accepted. If this fails with 400 or 413, the size limit fix is not working correctly."
|
|
1093
|
-
);
|
|
1094
|
-
|
|
1095
|
-
let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
|
|
1096
|
-
let results: Vec<serde_json::Value> = serde_json::from_slice(&body).unwrap();
|
|
1097
|
-
|
|
1098
|
-
assert_eq!(results.len(), 1);
|
|
1099
|
-
assert_eq!(results[0]["mime_type"], "text/plain");
|
|
1100
|
-
assert!(results[0]["content"].as_str().unwrap().contains("A"));
|
|
1101
|
-
}
|
|
1102
|
-
|
|
1103
|
-
/// Test extracting a 2MB file (just above the old Axum limit).
|
|
1104
|
-
///
|
|
1105
|
-
/// This tests the boundary case at exactly 2MB, which was the old Axum default limit.
|
|
1106
|
-
/// Files at this size should now be accepted with the DefaultBodyLimit::max() fix.
|
|
1107
|
-
#[tokio::test]
|
|
1108
|
-
async fn test_extract_2mb_file() {
|
|
1109
|
-
let app = create_router(ExtractionConfig::default());
|
|
1110
|
-
|
|
1111
|
-
let boundary = "----boundary";
|
|
1112
|
-
let file_content = "X".repeat(2 * 1024 * 1024);
|
|
1113
|
-
|
|
1114
|
-
let body_content = format!(
|
|
1115
|
-
"--{}\r\n\
|
|
1116
|
-
Content-Disposition: form-data; name=\"files\"; filename=\"boundary.txt\"\r\n\
|
|
1117
|
-
Content-Type: text/plain\r\n\
|
|
1118
|
-
\r\n\
|
|
1119
|
-
{}\r\n\
|
|
1120
|
-
--{}--\r\n",
|
|
1121
|
-
boundary, file_content, boundary
|
|
1122
|
-
);
|
|
1123
|
-
|
|
1124
|
-
let response = app
|
|
1125
|
-
.oneshot(
|
|
1126
|
-
Request::builder()
|
|
1127
|
-
.method("POST")
|
|
1128
|
-
.uri("/extract")
|
|
1129
|
-
.header("content-type", format!("multipart/form-data; boundary={}", boundary))
|
|
1130
|
-
.body(Body::from(body_content))
|
|
1131
|
-
.unwrap(),
|
|
1132
|
-
)
|
|
1133
|
-
.await
|
|
1134
|
-
.unwrap();
|
|
1135
|
-
|
|
1136
|
-
assert_eq!(
|
|
1137
|
-
response.status(),
|
|
1138
|
-
StatusCode::OK,
|
|
1139
|
-
"2MB file should be accepted (boundary case)"
|
|
1140
|
-
);
|
|
1141
|
-
|
|
1142
|
-
let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
|
|
1143
|
-
let results: Vec<serde_json::Value> = serde_json::from_slice(&body).unwrap();
|
|
1144
|
-
|
|
1145
|
-
assert_eq!(results.len(), 1);
|
|
1146
|
-
assert_eq!(results[0]["mime_type"], "text/plain");
|
|
1147
|
-
assert!(results[0]["content"].as_str().unwrap().contains("X"));
|
|
1148
|
-
}
|
|
1149
|
-
|
|
1150
|
-
/// Test extracting a 5MB file.
|
|
1151
|
-
///
|
|
1152
|
-
/// Verifies that files significantly larger than the old 2MB limit work correctly.
|
|
1153
|
-
#[tokio::test]
|
|
1154
|
-
async fn test_extract_5mb_file() {
|
|
1155
|
-
let app = create_router(ExtractionConfig::default());
|
|
1156
|
-
|
|
1157
|
-
let boundary = "----boundary";
|
|
1158
|
-
let file_content = "B".repeat(5 * 1024 * 1024);
|
|
1159
|
-
|
|
1160
|
-
let body_content = format!(
|
|
1161
|
-
"--{}\r\n\
|
|
1162
|
-
Content-Disposition: form-data; name=\"files\"; filename=\"medium.txt\"\r\n\
|
|
1163
|
-
Content-Type: text/plain\r\n\
|
|
1164
|
-
\r\n\
|
|
1165
|
-
{}\r\n\
|
|
1166
|
-
--{}--\r\n",
|
|
1167
|
-
boundary, file_content, boundary
|
|
1168
|
-
);
|
|
1169
|
-
|
|
1170
|
-
let response = app
|
|
1171
|
-
.oneshot(
|
|
1172
|
-
Request::builder()
|
|
1173
|
-
.method("POST")
|
|
1174
|
-
.uri("/extract")
|
|
1175
|
-
.header("content-type", format!("multipart/form-data; boundary={}", boundary))
|
|
1176
|
-
.body(Body::from(body_content))
|
|
1177
|
-
.unwrap(),
|
|
1178
|
-
)
|
|
1179
|
-
.await
|
|
1180
|
-
.unwrap();
|
|
1181
|
-
|
|
1182
|
-
assert_eq!(response.status(), StatusCode::OK, "5MB file should be accepted");
|
|
1183
|
-
|
|
1184
|
-
let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
|
|
1185
|
-
let results: Vec<serde_json::Value> = serde_json::from_slice(&body).unwrap();
|
|
1186
|
-
|
|
1187
|
-
assert_eq!(results.len(), 1);
|
|
1188
|
-
assert_eq!(results[0]["mime_type"], "text/plain");
|
|
1189
|
-
assert!(results[0]["content"].as_str().unwrap().contains("B"));
|
|
1190
|
-
}
|
|
1191
|
-
|
|
1192
|
-
/// Test extracting a 10MB file.
|
|
1193
|
-
///
|
|
1194
|
-
/// Verifies that moderately large files (10MB) are handled correctly.
|
|
1195
|
-
#[tokio::test]
|
|
1196
|
-
async fn test_extract_10mb_file() {
|
|
1197
|
-
let app = create_router(ExtractionConfig::default());
|
|
1198
|
-
|
|
1199
|
-
let boundary = "----boundary";
|
|
1200
|
-
let file_content = "C".repeat(10 * 1024 * 1024);
|
|
1201
|
-
|
|
1202
|
-
let body_content = format!(
|
|
1203
|
-
"--{}\r\n\
|
|
1204
|
-
Content-Disposition: form-data; name=\"files\"; filename=\"large.txt\"\r\n\
|
|
1205
|
-
Content-Type: text/plain\r\n\
|
|
1206
|
-
\r\n\
|
|
1207
|
-
{}\r\n\
|
|
1208
|
-
--{}--\r\n",
|
|
1209
|
-
boundary, file_content, boundary
|
|
1210
|
-
);
|
|
1211
|
-
|
|
1212
|
-
let response = app
|
|
1213
|
-
.oneshot(
|
|
1214
|
-
Request::builder()
|
|
1215
|
-
.method("POST")
|
|
1216
|
-
.uri("/extract")
|
|
1217
|
-
.header("content-type", format!("multipart/form-data; boundary={}", boundary))
|
|
1218
|
-
.body(Body::from(body_content))
|
|
1219
|
-
.unwrap(),
|
|
1220
|
-
)
|
|
1221
|
-
.await
|
|
1222
|
-
.unwrap();
|
|
1223
|
-
|
|
1224
|
-
assert_eq!(response.status(), StatusCode::OK, "10MB file should be accepted");
|
|
1225
|
-
|
|
1226
|
-
let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
|
|
1227
|
-
let results: Vec<serde_json::Value> = serde_json::from_slice(&body).unwrap();
|
|
1228
|
-
|
|
1229
|
-
assert_eq!(results.len(), 1);
|
|
1230
|
-
assert_eq!(results[0]["mime_type"], "text/plain");
|
|
1231
|
-
assert!(results[0]["content"].as_str().unwrap().contains("C"));
|
|
1232
|
-
}
|
|
1233
|
-
|
|
1234
|
-
/// Test extracting a 50MB file (half the default limit).
|
|
1235
|
-
///
|
|
1236
|
-
/// Verifies that very large files (50MB) are handled correctly,
|
|
1237
|
-
/// well within the 100MB default limit.
|
|
1238
|
-
#[tokio::test]
|
|
1239
|
-
async fn test_extract_50mb_file() {
|
|
1240
|
-
let app = create_router(ExtractionConfig::default());
|
|
1241
|
-
|
|
1242
|
-
let boundary = "----boundary";
|
|
1243
|
-
let file_content = "D".repeat(50 * 1024 * 1024);
|
|
1244
|
-
|
|
1245
|
-
let body_content = format!(
|
|
1246
|
-
"--{}\r\n\
|
|
1247
|
-
Content-Disposition: form-data; name=\"files\"; filename=\"very_large.txt\"\r\n\
|
|
1248
|
-
Content-Type: text/plain\r\n\
|
|
1249
|
-
\r\n\
|
|
1250
|
-
{}\r\n\
|
|
1251
|
-
--{}--\r\n",
|
|
1252
|
-
boundary, file_content, boundary
|
|
1253
|
-
);
|
|
1254
|
-
|
|
1255
|
-
let response = app
|
|
1256
|
-
.oneshot(
|
|
1257
|
-
Request::builder()
|
|
1258
|
-
.method("POST")
|
|
1259
|
-
.uri("/extract")
|
|
1260
|
-
.header("content-type", format!("multipart/form-data; boundary={}", boundary))
|
|
1261
|
-
.body(Body::from(body_content))
|
|
1262
|
-
.unwrap(),
|
|
1263
|
-
)
|
|
1264
|
-
.await
|
|
1265
|
-
.unwrap();
|
|
1266
|
-
|
|
1267
|
-
assert_eq!(response.status(), StatusCode::OK, "50MB file should be accepted");
|
|
1268
|
-
|
|
1269
|
-
let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
|
|
1270
|
-
let results: Vec<serde_json::Value> = serde_json::from_slice(&body).unwrap();
|
|
1271
|
-
|
|
1272
|
-
assert_eq!(results.len(), 1);
|
|
1273
|
-
assert_eq!(results[0]["mime_type"], "text/plain");
|
|
1274
|
-
assert!(results[0]["content"].as_str().unwrap().contains("D"));
|
|
1275
|
-
}
|
|
1276
|
-
|
|
1277
|
-
/// Test extracting a 90MB file (near the 100MB default limit).
|
|
1278
|
-
///
|
|
1279
|
-
/// Verifies that very large files close to the default limit (90MB out of 100MB)
|
|
1280
|
-
/// are handled correctly. This tests the upper boundary of the default configuration.
|
|
1281
|
-
#[tokio::test]
|
|
1282
|
-
async fn test_extract_90mb_file() {
|
|
1283
|
-
let app = create_router(ExtractionConfig::default());
|
|
1284
|
-
|
|
1285
|
-
let boundary = "----boundary";
|
|
1286
|
-
let file_content = "E".repeat(90 * 1024 * 1024);
|
|
1287
|
-
|
|
1288
|
-
let body_content = format!(
|
|
1289
|
-
"--{}\r\n\
|
|
1290
|
-
Content-Disposition: form-data; name=\"files\"; filename=\"huge.txt\"\r\n\
|
|
1291
|
-
Content-Type: text/plain\r\n\
|
|
1292
|
-
\r\n\
|
|
1293
|
-
{}\r\n\
|
|
1294
|
-
--{}--\r\n",
|
|
1295
|
-
boundary, file_content, boundary
|
|
1296
|
-
);
|
|
1297
|
-
|
|
1298
|
-
let response = app
|
|
1299
|
-
.oneshot(
|
|
1300
|
-
Request::builder()
|
|
1301
|
-
.method("POST")
|
|
1302
|
-
.uri("/extract")
|
|
1303
|
-
.header("content-type", format!("multipart/form-data; boundary={}", boundary))
|
|
1304
|
-
.body(Body::from(body_content))
|
|
1305
|
-
.unwrap(),
|
|
1306
|
-
)
|
|
1307
|
-
.await
|
|
1308
|
-
.unwrap();
|
|
1309
|
-
|
|
1310
|
-
assert_eq!(
|
|
1311
|
-
response.status(),
|
|
1312
|
-
StatusCode::OK,
|
|
1313
|
-
"90MB file should be accepted (within default 100MB limit)"
|
|
1314
|
-
);
|
|
1315
|
-
|
|
1316
|
-
let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
|
|
1317
|
-
let results: Vec<serde_json::Value> = serde_json::from_slice(&body).unwrap();
|
|
1318
|
-
|
|
1319
|
-
assert_eq!(results.len(), 1);
|
|
1320
|
-
assert_eq!(results[0]["mime_type"], "text/plain");
|
|
1321
|
-
assert!(results[0]["content"].as_str().unwrap().contains("E"));
|
|
1322
|
-
}
|
|
1323
|
-
|
|
1324
|
-
/// Test extracting a file over the 100MB default limit (HTTP 400/413).
|
|
1325
|
-
///
|
|
1326
|
-
/// Verifies that files exceeding the 100MB default limit are rejected
|
|
1327
|
-
/// with a 4xx error (typically HTTP 400 from tower-http RequestBodyLimitLayer or 413)
|
|
1328
|
-
/// rather than silently failing or accepting the request.
|
|
1329
|
-
#[tokio::test]
|
|
1330
|
-
async fn test_extract_file_over_default_limit() {
|
|
1331
|
-
let app = create_router(ExtractionConfig::default());
|
|
1332
|
-
|
|
1333
|
-
let boundary = "----boundary";
|
|
1334
|
-
let file_content = "F".repeat(101 * 1024 * 1024);
|
|
1335
|
-
|
|
1336
|
-
let body_content = format!(
|
|
1337
|
-
"--{}\r\n\
|
|
1338
|
-
Content-Disposition: form-data; name=\"files\"; filename=\"over_limit.txt\"\r\n\
|
|
1339
|
-
Content-Type: text/plain\r\n\
|
|
1340
|
-
\r\n\
|
|
1341
|
-
{}\r\n\
|
|
1342
|
-
--{}--\r\n",
|
|
1343
|
-
boundary, file_content, boundary
|
|
1344
|
-
);
|
|
1345
|
-
|
|
1346
|
-
let response = app
|
|
1347
|
-
.oneshot(
|
|
1348
|
-
Request::builder()
|
|
1349
|
-
.method("POST")
|
|
1350
|
-
.uri("/extract")
|
|
1351
|
-
.header("content-type", format!("multipart/form-data; boundary={}", boundary))
|
|
1352
|
-
.body(Body::from(body_content))
|
|
1353
|
-
.unwrap(),
|
|
1354
|
-
)
|
|
1355
|
-
.await
|
|
1356
|
-
.unwrap();
|
|
1357
|
-
|
|
1358
|
-
assert!(
|
|
1359
|
-
response.status() == StatusCode::BAD_REQUEST || response.status() == StatusCode::PAYLOAD_TOO_LARGE,
|
|
1360
|
-
"101MB file should be rejected with HTTP 400 or 413 (over 100MB default limit), got {}",
|
|
1361
|
-
response.status()
|
|
1362
|
-
);
|
|
1363
|
-
}
|
|
1364
|
-
|
|
1365
|
-
/// Test extracting multiple large files within limit.
|
|
1366
|
-
///
|
|
1367
|
-
/// Verifies that multiple large files can be uploaded together as long as
|
|
1368
|
-
/// the total size is within the default 100MB limit.
|
|
1369
|
-
#[tokio::test]
|
|
1370
|
-
async fn test_extract_multiple_large_files_within_limit() {
|
|
1371
|
-
let app = create_router(ExtractionConfig::default());
|
|
1372
|
-
|
|
1373
|
-
let boundary = "----boundary";
|
|
1374
|
-
let file1_content = "G".repeat(25 * 1024 * 1024);
|
|
1375
|
-
let file2_content = "H".repeat(25 * 1024 * 1024);
|
|
1376
|
-
let file3_content = "I".repeat(25 * 1024 * 1024);
|
|
1377
|
-
|
|
1378
|
-
let body_content = format!(
|
|
1379
|
-
"--{}\r\n\
|
|
1380
|
-
Content-Disposition: form-data; name=\"files\"; filename=\"file1.txt\"\r\n\
|
|
1381
|
-
Content-Type: text/plain\r\n\
|
|
1382
|
-
\r\n\
|
|
1383
|
-
{}\r\n\
|
|
1384
|
-
--{}\r\n\
|
|
1385
|
-
Content-Disposition: form-data; name=\"files\"; filename=\"file2.txt\"\r\n\
|
|
1386
|
-
Content-Type: text/plain\r\n\
|
|
1387
|
-
\r\n\
|
|
1388
|
-
{}\r\n\
|
|
1389
|
-
--{}\r\n\
|
|
1390
|
-
Content-Disposition: form-data; name=\"files\"; filename=\"file3.txt\"\r\n\
|
|
1391
|
-
Content-Type: text/plain\r\n\
|
|
1392
|
-
\r\n\
|
|
1393
|
-
{}\r\n\
|
|
1394
|
-
--{}--\r\n",
|
|
1395
|
-
boundary, file1_content, boundary, file2_content, boundary, file3_content, boundary
|
|
1396
|
-
);
|
|
1397
|
-
|
|
1398
|
-
let response = app
|
|
1399
|
-
.oneshot(
|
|
1400
|
-
Request::builder()
|
|
1401
|
-
.method("POST")
|
|
1402
|
-
.uri("/extract")
|
|
1403
|
-
.header("content-type", format!("multipart/form-data; boundary={}", boundary))
|
|
1404
|
-
.body(Body::from(body_content))
|
|
1405
|
-
.unwrap(),
|
|
1406
|
-
)
|
|
1407
|
-
.await
|
|
1408
|
-
.unwrap();
|
|
1409
|
-
|
|
1410
|
-
assert_eq!(
|
|
1411
|
-
response.status(),
|
|
1412
|
-
StatusCode::OK,
|
|
1413
|
-
"Multiple files totaling 75MB should be accepted"
|
|
1414
|
-
);
|
|
1415
|
-
|
|
1416
|
-
let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
|
|
1417
|
-
let results: Vec<serde_json::Value> = serde_json::from_slice(&body).unwrap();
|
|
1418
|
-
|
|
1419
|
-
assert_eq!(results.len(), 3, "Should have 3 results");
|
|
1420
|
-
for result in &results {
|
|
1421
|
-
assert_eq!(result["mime_type"], "text/plain");
|
|
1422
|
-
}
|
|
1423
|
-
assert!(results[0]["content"].as_str().unwrap().contains("G"));
|
|
1424
|
-
assert!(results[1]["content"].as_str().unwrap().contains("H"));
|
|
1425
|
-
assert!(results[2]["content"].as_str().unwrap().contains("I"));
|
|
1426
|
-
}
|
|
1427
|
-
|
|
1428
|
-
/// Test extracting multiple large files exceeding limit (HTTP 400/413).
|
|
1429
|
-
///
|
|
1430
|
-
/// Verifies that when multiple files together exceed the 100MB default limit,
|
|
1431
|
-
/// the request is rejected with a 4xx error (typically HTTP 400 or 413).
|
|
1432
|
-
#[tokio::test]
|
|
1433
|
-
async fn test_extract_multiple_large_files_exceeding_limit() {
|
|
1434
|
-
let app = create_router(ExtractionConfig::default());
|
|
1435
|
-
|
|
1436
|
-
let boundary = "----boundary";
|
|
1437
|
-
let file1_content = "J".repeat(50 * 1024 * 1024);
|
|
1438
|
-
let file2_content = "K".repeat(55 * 1024 * 1024);
|
|
1439
|
-
|
|
1440
|
-
let body_content = format!(
|
|
1441
|
-
"--{}\r\n\
|
|
1442
|
-
Content-Disposition: form-data; name=\"files\"; filename=\"file1.txt\"\r\n\
|
|
1443
|
-
Content-Type: text/plain\r\n\
|
|
1444
|
-
\r\n\
|
|
1445
|
-
{}\r\n\
|
|
1446
|
-
--{}\r\n\
|
|
1447
|
-
Content-Disposition: form-data; name=\"files\"; filename=\"file2.txt\"\r\n\
|
|
1448
|
-
Content-Type: text/plain\r\n\
|
|
1449
|
-
\r\n\
|
|
1450
|
-
{}\r\n\
|
|
1451
|
-
--{}--\r\n",
|
|
1452
|
-
boundary, file1_content, boundary, file2_content, boundary
|
|
1453
|
-
);
|
|
1454
|
-
|
|
1455
|
-
let response = app
|
|
1456
|
-
.oneshot(
|
|
1457
|
-
Request::builder()
|
|
1458
|
-
.method("POST")
|
|
1459
|
-
.uri("/extract")
|
|
1460
|
-
.header("content-type", format!("multipart/form-data; boundary={}", boundary))
|
|
1461
|
-
.body(Body::from(body_content))
|
|
1462
|
-
.unwrap(),
|
|
1463
|
-
)
|
|
1464
|
-
.await
|
|
1465
|
-
.unwrap();
|
|
1466
|
-
|
|
1467
|
-
assert!(
|
|
1468
|
-
response.status() == StatusCode::BAD_REQUEST || response.status() == StatusCode::PAYLOAD_TOO_LARGE,
|
|
1469
|
-
"Multiple files totaling 105MB should be rejected with HTTP 400 or 413, got {}",
|
|
1470
|
-
response.status()
|
|
1471
|
-
);
|
|
1472
|
-
}
|
|
@@ -3,8 +3,6 @@
|
|
|
3
3
|
//! Tests for ZIP, TAR, TAR.GZ, and 7z archive extraction.
|
|
4
4
|
//! Validates metadata extraction, content extraction, nested archives, and error handling.
|
|
5
5
|
|
|
6
|
-
#![cfg(feature = "archives")]
|
|
7
|
-
|
|
8
6
|
use kreuzberg::core::config::ExtractionConfig;
|
|
9
7
|
use kreuzberg::core::extractor::{extract_bytes, extract_bytes_sync};
|
|
10
8
|
use std::io::{Cursor, Write};
|