Module: AsyncZip

Defined in:
lib/async_zip/version.rb,
ext/async_zip.c

Defined Under Namespace

Classes: Error, Task

Constant Summary collapse

VERSION =
"1.0.0"

Class Method Summary collapse

Class Method Details

.create(files, zip_path) ⇒ Object

Add files to archive



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'ext/archive.c', line 45

static VALUE az_create(VALUE self, VALUE files, VALUE zip_path)
{
    rb_need_block();
    VALUE proc = rb_block_proc();

    int len = RARRAY_LEN(files);
    if(len > 0)
    {
        carray_str_t* parr = carray_str_create(len);

        int i;
        for(i = 0; i != len; ++i)
        {
            VALUE current = rb_ary_entry(files, i);
            if(rb_respond_to(current, rb_intern("to_s")))
            {
                VALUE name = rb_funcall(current, rb_intern("to_s"), 0);

                carray_str_set(parr, i, StringValuePtr(name));
            }
            else
            {
                carray_str_set(parr, i, NULL);
            }
        }

        archive_data_t* adata = az_make_archive_data(StringValuePtr(zip_path), NULL, parr);
        adata->proc = proc;

        rb_gc_register_address(&adata->proc);

        //
        az_enqueue_task(az_archive_thread_func, adata);
    }

    return self;
}

.extract(zip_path, dest_path) ⇒ Object

Extract files from archive



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'ext/archive.c', line 84

static VALUE az_extract(VALUE self, VALUE zip_path, VALUE dest_path)
{
    rb_need_block();
    VALUE proc = rb_block_proc();

    archive_data_t* adata = az_make_archive_data(StringValuePtr(zip_path), StringValuePtr(dest_path), NULL);
    adata->proc = proc;

    rb_gc_register_address(&adata->proc);

    //
    az_enqueue_task(az_archive_thread_func, adata);

    return self;
}