module CIO

For documentation - C library that stands either for C Input/Output or Cooplib Input/Output. Contains functions for IO that are much faster than the ruby standard functions

Public Instance Methods

copy_file(*args) click to toggle source

Exposes copy_file_base to ruby

VALUE rb_copy_file_base(int argc, VALUE *argv, VALUE self)
{
    if (argc > 3 || argc < 2) {  // There should only be 2..3 arguments
            rb_raise(rb_eArgError, "wrong number of arguments");
        }
        VALUE r_string_filename = StringValue(argv[0]);
        char *file_name = RSTRING_PTR(r_string_filename);
        VALUE r_string_destination = StringValue(argv[1]);
        char *destination = RSTRING_PTR(r_string_destination);
        VALUE r_read_size;
        if (argc == 3)
        {
            r_read_size = argv[2];
            copy_file(.file_name = file_name, .destination = destination, .read_size = FIX2INT(r_read_size));
        }
        else
        {
            copy_file(.file_name = file_name, .destination = destination);
        }
        return INT2FIX(does_file_exist(destination));
}
list_dirs(p1, p2) click to toggle source

Exposes the #list_dirs method to ruby

VALUE rb_list_dirs(VALUE self, VALUE directory, VALUE level)
{
    VALUE r_string_directory = StringValue(directory);

    char *dir = RSTRING_PTR(r_string_directory);
    int lev = FIX2INT(level);
    list_dirs(dir, lev);
    return Qnil;
}
read_file(*args) click to toggle source

Exposes read_file_base to ruby

VALUE rb_read_file_base(int argc, VALUE *argv, VALUE self)
{
    if (argc > 2 || argc < 1) {  // There should only be 1..2 arguments
                rb_raise(rb_eArgError, "wrong number of arguments");
            }
            VALUE r_string_filename = StringValue(argv[0]);
            char *file_path = RSTRING_PTR(r_string_filename);
            const char *buffer;
            VALUE r_read_size;
            if (argc == 2)
            {
                r_read_size = argv[1];
                int read_size = FIX2INT(r_read_size);
                buffer = read_file(.file_name = file_path, .read_size = read_size);
            }
            else
            {
                buffer = read_file(.file_name = file_path);
            }

        VALUE r_string = rb_str_new2(buffer);
        free((void *)buffer);
        return r_string;
}
write_new_file(p1, p2) click to toggle source

Exposes the #write_new_file function to ruby

VALUE rb_write_new_file(VALUE self, VALUE filename, VALUE data)
{
    VALUE r_string_filename = StringValue(filename);
    VALUE r_string_data = StringValue(data);

    char *file_path = RSTRING_PTR(r_string_filename);
    char *file_data = RSTRING_PTR(r_string_data);

    return INT2FIX(write_new_file(file_path, file_data));
}