How janko/down works
Main Components
• Down API: At the center is the primary API functions (Down.download and Down.open) which client applications call.
• Backend Modules: Represent the three interchangeable backends:
• Down::NetHttp (default using open-uri/Net::HTTP)
• Down::Http (uses the http.rb gem)
• Down::Httpx (uses the HTTPx gem)
• Streaming Component: Down::ChunkedIO – this handles the on-demand, chunked downloading and provides an IO-like interface.
• Download Configuration/Options: Components for handling options such as max file size, destination, authentication, headers, timeouts, etc.
• Error Handling: The custom exception hierarchy (e.g., Down::Error and its subclasses like Down::TooLarge, Down::InvalidUrl, etc.) that isolate and re-raise errors from different backends.
Relationships and Interactions
• The Down API delegates download and streaming requests to the configured backend.
• From each backend module, include a link showing dependency on underlying HTTP libraries or Ruby standard libraries (e.g., open-uri/Net::HTTP for Down::NetHttp, HTTP.rb for Down::Http, and HTTPx for Down::Httpx).
• For streaming operations, show Down::ChunkedIO being constructed by Down.open including options like caching vs. non-caching and wrapper over enumerators.
Important Architectural Patterns
• Separation of Concerns: The core “Down” module acts as a facade, abstracting away the details of the individual HTTP implementations.
• Configuration Flexibility: Backends are configurable, either by selecting one per method call or setting one globally.
• Exception Wrapping: Illustrate that all errors from low-level HTTP calls are caught and re-raised as Down-specific errors.
h. Optionally, include examples of parameters such as "max_size", "destination", and settings specific to each HTTP gem, perhaps as small callouts near each backend module.
Final Touches
• Every component is clearly labeled with concise text.