class Zip::Stat

Public Instance Methods

comp_method() click to toggle source
VALUE zipruby_stat_comp_method(VALUE self) {
  struct zipruby_stat *p_stat;

  Data_Get_Struct(self, struct zipruby_stat, p_stat);

  return INT2NUM(p_stat->sb->comp_method);
}
comp_size() click to toggle source
VALUE zipruby_stat_comp_size(VALUE self) {
  struct zipruby_stat *p_stat;

  Data_Get_Struct(self, struct zipruby_stat, p_stat);

  return LONG2NUM(p_stat->sb->comp_size);
}
crc() click to toggle source
VALUE zipruby_stat_crc(VALUE self) {
  struct zipruby_stat *p_stat;

  Data_Get_Struct(self, struct zipruby_stat, p_stat);

  return UINT2NUM(p_stat->sb->crc);
}
directory?() click to toggle source
VALUE zipruby_stat_is_directory(VALUE self) {
  struct zipruby_stat *p_stat;
  const char *name;
  size_t name_len;
  off_t size;

  Data_Get_Struct(self, struct zipruby_stat, p_stat);
  name = p_stat->sb->name;
  size = p_stat->sb->size;

  if (!name || size != 0) {
    return Qfalse;
  }

  name_len = strlen(name);

  if (name_len > 0 && name[name_len - 1] == '/') {
    return Qtrue;
  } else {
    return Qfalse;
  }
}
encryption_method() click to toggle source
VALUE zipruby_stat_encryption_method(VALUE self) {
  struct zipruby_stat *p_stat;

  Data_Get_Struct(self, struct zipruby_stat, p_stat);

  return INT2NUM(p_stat->sb->encryption_method);
}
index() click to toggle source
VALUE zipruby_stat_index(VALUE self) {
  struct zipruby_stat *p_stat;

  Data_Get_Struct(self, struct zipruby_stat, p_stat);

  return INT2NUM(p_stat->sb->index);
}
mtime() click to toggle source
VALUE zipruby_stat_mtime(VALUE self) {
  struct zipruby_stat *p_stat;

  Data_Get_Struct(self, struct zipruby_stat, p_stat);

  return rb_funcall(rb_cTime, rb_intern("at"), 1,  LONG2NUM((long) p_stat->sb->mtime));
}
name() click to toggle source
VALUE zipruby_stat_name(VALUE self) {
  struct zipruby_stat *p_stat;

  Data_Get_Struct(self, struct zipruby_stat, p_stat);

  return p_stat->sb->name ? rb_str_new2(p_stat->sb->name) : Qnil;
}
size() click to toggle source
VALUE zipruby_stat_size(VALUE self) {
  struct zipruby_stat *p_stat;

  Data_Get_Struct(self, struct zipruby_stat, p_stat);

  return LONG2NUM(p_stat->sb->size);
}

Public Class Methods

new(p1, p2, p3 = v3) click to toggle source
static VALUE zipruby_stat_initialize(int argc, VALUE *argv, VALUE self) {
  VALUE archive, index, flags;
  struct zipruby_archive *p_archive;
  struct zipruby_stat *p_stat;
  char *fname = NULL;
  int i_index = -1, i_flags = 0;

  rb_scan_args(argc, argv, "21", &archive, &index, &flags);

  if (!rb_obj_is_instance_of(archive, Archive)) {
    rb_raise(rb_eTypeError, "wrong argument type %s (expected Zip::Archive)", rb_class2name(CLASS_OF(archive)));
  }

  switch (TYPE(index)) {
  case T_STRING: fname = RSTRING_PTR(index); break;
  case T_FIXNUM: i_index = NUM2INT(index); break;
  default:
    rb_raise(rb_eTypeError, "wrong argument type %s (expected String or Fixnum)", rb_class2name(CLASS_OF(index)));
  }

  if (!NIL_P(flags)) {
    i_flags = NUM2INT(flags);
  }

  Data_Get_Struct(archive, struct zipruby_archive, p_archive);
  Check_Archive(p_archive);
  Data_Get_Struct(self, struct zipruby_stat, p_stat);

  if (fname) {
    if (zip_stat(p_archive->archive, fname, i_flags, p_stat->sb) != 0) {
      rb_raise(Error, "Obtain file status failed - %s: %s", fname, zip_strerror(p_archive->archive));
    }
  } else {
    if (zip_stat_index(p_archive->archive, i_index, i_flags, p_stat->sb) != 0) {
      rb_raise(Error, "Obtain file status failed at %d: %s", i_index, zip_strerror(p_archive->archive));
    }
  }

  return Qnil;
}