Skip to content

Instantly share code, notes, and snippets.

@k3rni
Created March 11, 2014 12:28
Show Gist options
  • Save k3rni/9484634 to your computer and use it in GitHub Desktop.
Save k3rni/9484634 to your computer and use it in GitHub Desktop.
simplest possible ruby bzip2 library
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