= ruby-xz

<b>ruby-xz</b> is a basic binding to the famous
{liblzma library}[http://tukaani.org/xz/], best known for the
extreme compression-ratio it's native +XZ+ format achieves. ruby-xz gives
you the possibility of creating and extracting XZ archives on any platform
where liblzma is installed. No compilation is needed, because ruby-xz is
written ontop of ffi[https://github.com/ffi/ffi].

ruby-xz supports both "intuitive" (de)compression by providing methods to
directly operate on strings and files, but also allows you to operate
directly on IO streams (see the various methods of the XZ module). On top
of that, ruby-xz offers an advanced interface that allows you to treat
XZ-compressed data as IO streams, both for reading and for writing. See the
XZ::StreamReader and XZ::StreamWriter classes for more information on this.

== Installation

Install it the way you install all your gems.

  # gem install ruby-xz

Although it is designed for Ruby 1.9 (which I highly recommend),
ruby-xz should also work with Ruby 1.8.7. However, the Ruby 1.8
compatibility may be skipped anytime (causing at least a minor version
bump), so you shouldn’t rely on it.

== Usage

The documentation of the XZ module is well and you should be able to find
everything you need to use ruby-xz. As said, it's not big, but powerful:
You can create and extract whole archive files, compress or decompress
streams of data or just plain strings.

=== First step

You have to require ruby-xz. Note the file you have to require is named
"xz.rb", so do

  require "xz"
  
to get it.

=== Examples

  #Compress a TAR archive
  XZ.compress_file("myfile.tar", "myfile.tar.xz")
  #Decompress it
  XZ.decompress_file("myfile.tar.xz", "myfile.tar")
  
  #Compress everything you get from a socket (note that there HAS to be a EOF
  #sometime, otherwise this will run infinitely)
  XZ.compress_stream(socket){|chunk| opened_file.write(chunk)}
  
  #Compress a string
  comp = XZ.compress("Mydata")
  #Decompress it
  data = XZ.decompress(comp)

Have a look at the XZ module's documentation for an in-depth description of
what is possible.

=== License

(The MIT License)

Basic liblzma-bindings for Ruby.

Copyright © 2011,2012 Marvin Gülker

Copyright © 2011 Christoph Plank

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the ‘Software’),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

==== require_relative

This library includes the sourcecode of Steve Klabnik’s
{require_relative gem}[http://steveklabnik.github.com/require_relative/]
in order to make it 1.8-compatible. It’s licensed under the BSD license:

Copyright (c) 2011, Steve Klabnik

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
  notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
  notice, this list of conditions and the following disclaimer in the
  documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.