diff options
| author | Adam Vandenberg | 2012-04-29 11:45:46 -0700 |
|---|---|---|
| committer | Adam Vandenberg | 2012-05-02 19:57:33 -0700 |
| commit | 3ad19e08b710eabb64a932df2fb359a260f4ae7b (patch) | |
| tree | af37fc5e7b9caa50930e55f5736b384e4d5b4435 /Library/Homebrew/extend/pathname.rb | |
| parent | 837d206a628712f823f5f06c3fda6ac952af9e22 (diff) | |
| download | brew-3ad19e08b710eabb64a932df2fb359a260f4ae7b.tar.bz2 | |
Extract detection of compression types
Separate out detecting compression types from uncompressing and staging.
Diffstat (limited to 'Library/Homebrew/extend/pathname.rb')
| -rw-r--r-- | Library/Homebrew/extend/pathname.rb | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/Library/Homebrew/extend/pathname.rb b/Library/Homebrew/extend/pathname.rb index 3dda828d5..515356861 100644 --- a/Library/Homebrew/extend/pathname.rb +++ b/Library/Homebrew/extend/pathname.rb @@ -240,6 +240,31 @@ class Pathname nil end + def compression_type + # Don't treat jars as compressed + return nil if self.extname == '.jar' + + # OS X installer package + return :pkg if self.extname == '.pkg' + + # get the first six bytes + magic_bytes = nil + File.open(self) { |f| magic_bytes = f.read(6) } + + # magic numbers stolen from /usr/share/file/magic/ + case magic_bytes + when /^PK\003\004/ then :zip + when /^\037\213/ then :gzip + when /^BZh/ then :bzip2 + when /^\037\235/ then :compress + when /^\xFD7zXZ\x00/ then :xz + when /^Rar!/ then :rar + else + # Assume it is not an archive + nil + end + end + def incremental_hash(hasher) incr_hash = hasher.new self.open('r') do |f| |
