Down is a small, reliable Ruby library for downloading files that favors correctness, streaming, and clear error handling. It follows redirects safely, supports timeouts and retries, and streams responses to disk to keep memory usage low—ideal for large downloads or server environments. The API returns file-like objects (often Tempfile) with helpful metadata such as original filename and content type, which plays nicely with file-attachment libraries and background jobs. Multiple HTTP backends are supported, letting you choose between Net::HTTP or faster/feature-rich clients while keeping a consistent interface. It exposes distinct exception classes and content validation options, so callers can differentiate transient network issues from invalid responses. In practice, Down is often used as the dependable download layer in upload/processing pipelines where robustness matters more than raw feature bloat.
Features
- Streaming download of remote files to disk or tempfiles, avoiding loading entire file into memory unnecessarily
- Ability to specify maximum file size to protect against huge or malicious downloads (via content-length or early aborts)
- Choice of HTTP backends: Net::HTTP (standard library), http.rb, HTTPX etc.
- Ability to set destination path rather than always using a tempfile, override file extension, prefix names etc.
- Metadata extraction: content type, original filename, charset etc from the HTTP response headers
- Support for streaming open (reading while downloading) as well as complete file download, with options for timeouts etc.