Skip to content
Original libbz2 ruby C bindings from Guy Decoux, with some new love
C Ruby
Find file
Latest commit e58f154 Jun 26, 2013 @brianmario Revert "Revert "fix memory leaks in bz_reader_read""
This reverts commit 69766a7.
Failed to load latest commit information.
.yardopts Wrap up documentation of the Bzip2::Writer class. Oct 12, 2010
Gemfile more formatting Feb 13, 2013
Rakefile move to rake-compiler Jan 27, 2011
bzip2-ruby.gemspec Remove extra_rdoc_files because documentation is in Markdown format Mar 7, 2013

Ruby C bindings to libbzip2


First make sure you’ve got Gemcutter in your sources list:

gem sources -a

Then go ahead and install it as usual:

sudo gem install bzip2-ruby

You may need to specify:

--with-bz2-dir=<include file directory for libbzip2>

Or in a Gemfile

gem 'bzip2-ruby'


The full documentation is hosted on

Here's a quick overview, hower:

require 'bzip2'

# Quick shortcuts
data = Bzip2.compress 'string'
Bzip2.uncompress data

# Creating a bz2 compressed file
writer ='file')
writer << 'data1'
writer.puts 'data2'
writer.print 'data3'
writer.printf '%s', 'data4'
writer.close'file'){ |f| f << data }

# Reading a bz2 compressed file
reader ='file')
reader.gets # => "data1data2\n" # => 'data3data4'

reader.readline # => raises Bzip2::EOZError'file'){ |f| puts }


This extension module is copyrighted free software by Guy Decoux
You can redistribute it and/or modify it under the same term as Ruby.
Guy Decoux <>

Modifications from origin version

  • Switch to Jeweler
  • Renamed BZ2 module/namespace to Bzip2
  • Renamed compiled binary from "bz2" to "bzip2"
  • Renamed gem from "bz2" to "bzip2-ruby"
  • Converted original tests to rspec
  • 1.9 compatibility
Something went wrong with that request. Please try again.