# module Tioga::Flate

### Public Class Methods

compress(str) → string click to toggle source

Returns a compressed verion of str in a new string.

    VALUE do_compress(VALUE klass, VALUE str) {
       str = rb_String(str);
       unsigned char *ptr = (unsigned char *)RSTRING_PTR(str);
       long len = RSTRING_LEN(str);
       unsigned long new_len = (len * 11) / 10 + 100;
       unsigned char *new_ptr = ALLOC_N(unsigned char, new_len);
       if (flate_compress(new_ptr, &new_len, ptr, len) != Z_OK) {
          free(new_ptr);
          rb_raise(rb_eArgError, "Error in Flate.compress");
       }
       VALUE new_str = rb_str_new((char *)new_ptr, new_len);
       free(new_ptr);
       return new_str;
    }

expand(str) → string click to toggle source

Returns a decompressed verion of str in a new string. Assumes that str was compressed using `Flate.compress`.

    VALUE do_expand(VALUE klass, VALUE str) {
       str = rb_String(str);
       unsigned char *ptr = (unsigned char *)RSTRING_PTR(str);
       long len = RSTRING_LEN(str);
       unsigned long new_len = len * 4 + 100;
       unsigned char *new_ptr = ALLOC_N(unsigned char, new_len);
       if (flate_expand(&new_ptr, &new_len, ptr, len) != Z_OK) {
          free(new_ptr);
          rb_raise(rb_eArgError, "Error in Flate.expand");
       }
       VALUE new_str = rb_str_new((char *)new_ptr, new_len);
       free(new_ptr);
       return new_str;
    }