Class: Archive::Writer
- Inherits:
-
Object
- Object
- Archive::Writer
- Defined in:
- ext/libarchive_writer.c
Class Method Summary collapse
- .open_filename(v_filename, v_compression, v_format) ⇒ Object
- .open_memory(v_memory, v_compression, v_format) ⇒ Object
Instance Method Summary collapse
- #close ⇒ Object
- #compression ⇒ Object
- #compression_name ⇒ Object
- #format ⇒ Object
- #format_name ⇒ Object
- #new_entry ⇒ Object
- #position_compressed ⇒ Object
- #position_uncompressed ⇒ Object
- #write_data(*args) ⇒ Object
- #write_header(v_entry) ⇒ Object
Class Method Details
.open_filename(v_filename, v_compression, v_format) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'ext/libarchive_writer.c', line 83
static VALUE rb_libarchive_writer_s_open_filename(VALUE self, VALUE v_filename, VALUE v_compression, VALUE v_format) {
const char *filename = NULL;
int compression, format;
const char *cmd = NULL;
Check_Type(v_filename, T_STRING);
if (RSTRING_LEN(v_filename) < 1) {
rb_raise(rb_eArchiveError, "Open writer failed: No such file or directory");
}
filename = RSTRING_PTR(v_filename);
if (T_STRING == TYPE(v_compression)) {
compression = -1;
cmd = RSTRING_PTR(v_compression);
} else {
compression = NUM2INT(v_compression);
}
format = NUM2INT(v_format);
return rb_libarchive_writer_s_open0(rb_libarchive_writer_s_open_filename0, (void *) filename, compression, format, cmd);
}
|
.open_memory(v_memory, v_compression, v_format) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'ext/libarchive_writer.c', line 114
static VALUE rb_libarchive_writer_s_open_memory(VALUE self, VALUE v_memory, VALUE v_compression, VALUE v_format) {
int compression, format;
const char *cmd = NULL;
Check_Type(v_memory, T_STRING);
if (T_STRING == TYPE(v_compression)) {
compression = -1;
cmd = RSTRING_PTR(v_compression);
} else {
compression = NUM2INT(v_compression);
}
format = NUM2INT(v_format);
return rb_libarchive_writer_s_open0(rb_libarchive_writer_s_open_memory0, (void *) v_memory, compression, format, cmd);
}
|
Instance Method Details
#close ⇒ Object
15 16 17 18 19 20 21 |
# File 'ext/libarchive_writer.c', line 15
static VALUE rb_libarchive_writer_close(VALUE self) {
struct rb_libarchive_archive_container *p;
Data_Get_Struct(self, struct rb_libarchive_archive_container, p);
Check_Archive(p);
rb_libarchive_writer_close0(p);
return Qnil;
}
|
#compression ⇒ Object
48 49 50 51 52 53 |
# File 'ext/libarchive_archive.c', line 48
static VALUE rb_libarchive_archive_compression(VALUE self) {
struct rb_libarchive_archive_container *p;
Data_Get_Struct(self, struct rb_libarchive_archive_container, p);
Check_Archive(p);
return INT2NUM(archive_compression(p->ar));
}
|
#compression_name ⇒ Object
40 41 42 43 44 45 |
# File 'ext/libarchive_archive.c', line 40
static VALUE rb_libarchive_archive_compression_name(VALUE self) {
struct rb_libarchive_archive_container *p;
Data_Get_Struct(self, struct rb_libarchive_archive_container, p);
Check_Archive(p);
return rb_str_new2(archive_compression_name(p->ar));
}
|
#format ⇒ Object
64 65 66 67 68 69 |
# File 'ext/libarchive_archive.c', line 64
static VALUE rb_libarchive_archive_format(VALUE self) {
struct rb_libarchive_archive_container *p;
Data_Get_Struct(self, struct rb_libarchive_archive_container, p);
Check_Archive(p);
return NUM2INT(archive_format(p->ar));
}
|
#format_name ⇒ Object
56 57 58 59 60 61 |
# File 'ext/libarchive_archive.c', line 56
static VALUE rb_libarchive_archive_format_name(VALUE self) {
struct rb_libarchive_archive_container *p;
Data_Get_Struct(self, struct rb_libarchive_archive_container, p);
Check_Archive(p);
return rb_str_new2(archive_format_name(p->ar));
}
|
#new_entry ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'ext/libarchive_writer.c', line 131
static VALUE rb_libarchive_writer_new_entry(VALUE self) {
VALUE entry;
struct rb_libarchive_archive_container *p;
struct archive_entry *ae;
Data_Get_Struct(self, struct rb_libarchive_archive_container, p);
Check_Archive(p);
if ((ae = archive_entry_new()) == NULL) {
rb_raise(rb_eArchiveError, "New entry failed: %s", strerror(errno));
}
entry = rb_libarchive_entry_new(ae, 1);
if (rb_block_given_p()) {
VALUE retval;
int status;
retval = rb_protect(rb_yield, entry, &status);
rb_libarchive_entry_close(entry);
if (status != 0) {
rb_jump_tag(status);
}
return retval;
} else {
return entry;
}
}
|
#position_compressed ⇒ Object
24 25 26 27 28 29 |
# File 'ext/libarchive_archive.c', line 24
static VALUE rb_libarchive_archive_position_compressed(VALUE self) {
struct rb_libarchive_archive_container *p;
Data_Get_Struct(self, struct rb_libarchive_archive_container, p);
Check_Archive(p);
return LONG2NUM(archive_position_compressed(p->ar));
}
|
#position_uncompressed ⇒ Object
32 33 34 35 36 37 |
# File 'ext/libarchive_archive.c', line 32
static VALUE rb_libarchive_archive_position_uncompressed(VALUE self) {
struct rb_libarchive_archive_container *p;
Data_Get_Struct(self, struct rb_libarchive_archive_container, p);
Check_Archive(p);
return LONG2NUM(archive_position_uncompressed(p->ar));
}
|
#write_data(*args) ⇒ Object
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'ext/libarchive_writer.c', line 202
static VALUE rb_libarchive_writer_write_data(int argc, VALUE *argv, VALUE self) {
struct rb_libarchive_archive_container *p;
Data_Get_Struct(self, struct rb_libarchive_archive_container, p);
Check_Archive(p);
if (rb_block_given_p()) {
ssize_t len = 0;
if (argc > 0) {
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0)", argc);
}
while(1) {
VALUE retval;
ssize_t n;
retval = rb_yield(Qnil);
if ((n = rb_libarchive_writer_write_data0(p->ar, retval)) < 1) {
return LONG2NUM(len);
}
len += n;
}
} else {
VALUE v_buff;
ssize_t n;
rb_scan_args(argc, argv, "10", &v_buff);
n = rb_libarchive_writer_write_data0(p->ar, v_buff);
return LONG2NUM(n);
}
}
|
#write_header(v_entry) ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'ext/libarchive_writer.c', line 161
static VALUE rb_libarchive_writer_write_header(VALUE self, VALUE v_entry) {
struct rb_libarchive_archive_container *pa;
struct rb_libarchive_entry_container *pae;
Check_Class(v_entry, rb_cArchiveEntry);
Data_Get_Struct(self, struct rb_libarchive_archive_container, pa);
Check_Archive(pa);
Data_Get_Struct(v_entry, struct rb_libarchive_entry_container, pae);
Check_Entry(pae);
if (archive_write_header(pa->ar, pae->ae) != ARCHIVE_OK) {
rb_raise(rb_eArchiveError, "Write header failed: %s", archive_error_string(pa->ar));
}
return Qnil;
}
|