class Bzip2

Public Class Methods

bunzip2(*args)
Alias for: uncompress
bzip2(*args)
Alias for: compress
compress(str) click to toggle source

Shortcut for compressing just a string.

Bzip2.uncompress Bzip2.compress('data') # => 'data'

@param [String] str the string to compress @return [String] str compressed with bz2

static VALUE bz_compress(int argc, VALUE *argv, VALUE obj) {
    VALUE bz2, str;

    if (!argc) {
        rb_raise(rb_eArgError, "need a String to compress");
    }
    str = rb_str_to_str(argv[0]);
    argv[0] = Qnil;
    bz2 = rb_funcall2(bz_cWriter, id_new, argc, argv);
    if (OBJ_TAINTED(str)) {
        struct bz_file *bzf;
        Data_Get_Struct(bz2, struct bz_file, bzf);
        OBJ_TAINT(bzf->io);
    }
    bz_writer_write(bz2, str);
    return bz_writer_close(bz2);
}
Also aliased as: bzip2
decompress(*args)
Alias for: uncompress
uncompress(data) click to toggle source
Decompress a string of bz2 compressed data.
Bzip2.uncompress Bzip2.compress('asdf') # => 'asdf'

@param [String] data bz2 compressed data @return [String] data as uncompressed bz2 data @raise [Bzip2::Error] if data is not valid bz2 data

static VALUE bz_uncompress(int argc, VALUE *argv, VALUE obj) {
    VALUE bz2, nilv = Qnil;

    if (!argc) {
        rb_raise(rb_eArgError, "need a String to Uncompress");
    }
    argv[0] = rb_str_to_str(argv[0]);
    bz2 = rb_funcall2(bz_cReader, id_new, argc, argv);
    return bz_reader_read(1, &nilv, bz2);
}
Also aliased as: decompress, bunzip2