36 lines
2.0 KiB
Markdown
36 lines
2.0 KiB
Markdown
# Compress Files
|
|
|
|
## Instructions
|
|
|
|
1. Ensure Python and [Flask](https://flask.palletsprojects.com/) are installed
|
|
3. Run `python main.py`
|
|
4. Navigate to http://localhost:8888
|
|
|
|
## Design Considerations and Key Decisions
|
|
|
|
The project consisted of both a frontend and backend component. The frontend only required a straightforward web interface solely for file upload and display of compressed file details, thus a static HTML file sufficed.
|
|
|
|
For the backend, a REST API was essential to facilitate file uploads and subsequent downloads of compressed files:
|
|
- `/api/upload_file`
|
|
- Accepts HTTP POST requests containing the file to compress
|
|
- Returns a JSON object including fields: `{"compressed_size":INT,"file_id":STR,"original_size":INT}`
|
|
- Essential information for user display and compressed file retrieval
|
|
- `/api/download_file/<FILE_ID>`
|
|
- Accepts HTTP GET requests
|
|
- Retrieves the compressed file corresponding to `FILE_ID`
|
|
|
|
Python Flask was selected for the backend due to its suitability for developing REST APIs.
|
|
|
|
Upon file upload, the backend saves and compresses the file, subsequently deleting the original. Each file is uniquely identified using a UUIDv4 to prevent naming conflicts.
|
|
|
|
### Other considerations
|
|
|
|
For scalability, multithreading could enhance performance with increased load and larger files, but this was beyond the project's current scope.
|
|
|
|
Decompression functionality was not required for this project. However, if needed, decompression details could be stored server-side (e.g., in JSON files linked to each file ID) or within the compressed file itself.
|
|
|
|
## Compression Algorithm
|
|
|
|
Research revealed no standardized format for ECG files, limiting optimization options for headers or data structures.
|
|
|
|
The Huffman Coding algorithm was chosen for its proven reliability. Opting for a 1-byte node representation was determined to be optimal despite initially considering for 3-byte nodes, owing to the algorithm's efficiency with only 256 possible combinations. |