Downloading files on the DL
Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
test
.document
.gitignore
LICENSE
README.rdoc
Rakefile
downlow.gemspec

README.rdoc

downlow

Downloading files on the DL

Installation

gem install downlow

Tested against Ruby 1.8.7 and 1.9.1

What

Why is downloading and extracting files such a pain in Ruby?

Downlow to the rescue.

$ irb -rubygems -rdownlow
>> DL('http://gist.github.com/gists/290151/download', '~/Desktop/gist')
=> #<Pathname:/Users/aaronquint/Desktop/gist>

$ ls -l ~/Desktop/gist/
total 8
drwxrwxr-x  3 aaronquint  aaronquint  102 Jan 30 00:17 gist290151-4d195b0fc72a4b5e52f8e2b5d1670d078c03a018

>> DL('git://github.com/quirkey/resque-status.git', '~/Desktop')
Initialized empty Git repository in /Users/aaronquint/Sites/__active/downlow/tmp/resque-status/.git/
remote: Counting objects: 323, done.
remote: Compressing objects: 100% (186/186), done.
remote: Total 323 (delta 166), reused 169 (delta 83)
Receiving objects: 100% (323/323), 42.84 KiB, done.
Resolving deltas: 100% (166/166), done.
=> #<Pathname:/Users/aaronquint/Desktop/resque-status>

Sweet.

BONUS BEATS FOR GITHUB Downloads the tarball and extracts.

>> DL('gh://quirkey/sammy', ~/Desktop')

Usage

Downlow is comprised of two main features: Fetchers and Extractors. They do what they sound like they do.

To just fetch a remote (or local file or directory)

Downlow::Fetcher.fetch('remote', :destination => 'local')

Fetcher currently handles these styles of URL

Git (git://)
HTTP (http://)
Github (gh://user/project)
Local (anything else)

Extractors take a local file, and extract them based on their extension:

Downlow::Extractor.extract('local.archive', :destination => 'directory')

The extractors currently supported are

.tar.gz
.zip
dir (everything else)

DL() is just an alias for Downlow.get() which is just a wrapper around .fetch() and then .extract()

Thanks

Thanks to @mxcl for the awesome pathname extensions in homebrew/ Thanks to @defunkt as I took some ideas from rip.

Note on Patches/Pull Requests

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don't break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches.

Copyright

Copyright © 2010 Aaron Quint. See LICENSE for details.