processor.rs) handles file validation, image conversion to WebP format, and ZIP archive creation.
Constants
Validation Limits
Allowed File Extensions
The processor supports the following file types:- Images: jpg, jpeg, png, gif, bmp, tiff, tif, webp, heic, heif, svg, ico, raw, cr2, nef, arw
- Documents: pdf, doc, docx, xls, xlsx, ppt, pptx, txt, rtf, csv, md, markdown, pages, numbers, key
- Archives: zip, tar, gz, 7z, rar, bz2, xz, tgz
- Video: mov, mp4, avi, mkv, webm, m4v, wmv, flv, 3gp
- Audio: mp3, wav, aac, flac, m4a, ogg, wma, aiff
- Code & Data: json, xml, html, css, js, ts, jsx, tsx, py, rs, go, swift, java, c, cpp, h, rb, php, sh, bash, zsh, yaml, yml, toml, ini, sql, graphql
- macOS/Apps: dmg, pkg, app, ipa
- Fonts: ttf, otf, woff, woff2, eot
- Other: log, env, gitignore, dockerfile
Data Structures
ProcessResult
Returned by all processing functions to indicate the result of file processing.Path to the processed output file
Total size of input file(s) in bytes
Size of output file in bytes (after compression/conversion)
Output file extension (“webp”, “zip”, or original extension)
ValidationError
Error type returned when file validation fails.Human-readable error message
Optional path to the file that caused the error
Functions
validate_files
Validates files before processing to ensure they meet size and type requirements.Array of file paths to validate
Result<(), ValidationError>
Validation Checks:
- At least one file is provided
- No more than
MAX_FILES(50) files - Each file exists and is not a directory
- Each file is under
MAX_SINGLE_FILE_SIZE(500MB) - Total size is under
MAX_TOTAL_SIZE(1GB) - File extensions are in the allowed list (if extension present)
convert_to_webp
Converts image files (jpg, jpeg, png, gif, bmp, tiff, tif) to WebP format at 80% quality.Path to the input image file
Directory where the WebP file will be saved
Result<ProcessResult, String>
Behavior:
- Generates unique filename:
{stem}_{8-char-uuid}.webp - Uses 80% quality WebP compression
- Preserves original filename stem
- Returns original and processed file sizes
create_zip
Creates a ZIP archive from multiple files using Deflate compression.Array of file paths to include in the archive
Directory where the ZIP file will be saved
Result<ProcessResult, String>
Behavior:
- Generates unique filename:
archive_{8-char-uuid}.zip - Uses Deflate compression method
- Preserves original filenames inside the archive
- Calculates total original size of all input files
process_files
Main processing function that applies the ZipDrop logic based on file count and type.Vector of file paths to process
Directory where processed files will be saved
Result<ProcessResult, String>
Processing Logic:
Flow Diagram:
Example Usage:
Error Handling
All functions returnResult types with descriptive error messages:
- File I/O errors: “Failed to read file metadata”, “Failed to create output file”
- Image processing errors: “Failed to open image”, “Failed to write WebP”
- ZIP errors: “Failed to create zip file”, “Failed to write to zip”
- Validation errors: See
ValidationErrorexamples above
Files without extensions are allowed and will be treated as binary files. The output will preserve the filename with a unique ID suffix.