Class: Archive::Writer

### Home Classes Methods

### In Files

- libarchive.c

### Parent

Object

### Methods

- ::open_filename
- ::open_memory
- #close
- #compression
- #compression_name
- #format
- #format_name
- #new_entry
- #position_compressed
- #position_uncompressed
- #write_data
- #write_header

### Files

- README.txt

### Class/Module Index

Quicksearch

- Archive
- Archive::Entry
- Archive::Error
- Archive::Reader
- Archive::Writer

No matching classes.

# Archive::Writer

### Public Class Methods

open_filename(p1, p2, p3) click to toggle source

    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(p1, p2, p3) click to toggle source

    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);
    }

### Public Instance Methods

close() click to toggle source

    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() click to toggle source

    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() click to toggle source

    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() click to toggle source

    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() click to toggle source

    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() click to toggle source

    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() click to toggle source

    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 LL2NUM(archive_position_compressed(p->ar));
    }

position_uncompressed() click to toggle source

    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 LL2NUM(archive_position_uncompressed(p->ar));
    }

write_data(p1) click to toggle source

    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(p1) click to toggle source

    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;
    }

[Validate]

Generated with the Darkfish Rdoc Generator 2.