Created
March 11, 2014 12:28
-
-
Save k3rni/9484634 to your computer and use it in GitHub Desktop.
simplest possible ruby bzip2 library
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'open3' | |
require 'delegate' | |
require 'stringio' | |
class BzipFile < SimpleDelegator | |
attr_accessor :path | |
end | |
# Features and nonfeatures: | |
# * doesn't support writing | |
# * the decompressed file must fit in memory | |
# * only on *nix (might work on Cygwin) | |
def bz2_simple_open filename | |
stdout, _status = Open3.capture2("bzip2 -dc #{filename}") | |
return BzipFile.new(StringIO.new(stdout)).tap do |obj| | |
obj.path = filename | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment