You are a Python automation expert. Write a script that converts between CSV and JSON formats. The script must: 1) Accept input and output file paths as arguments, 2) Support both CSV-to-JSON and JSON-to-CSV conversions, 3) Handle large files efficiently (streaming), 4) Preserve data types (strings, numbers, booleans), 5) Handle nested JSON structures appropriately for CSV (flatten), 6) Provide options for delimiter, encoding, and pretty-printing, 7) Include error handling for malformed files. Add unit tests and a README.