Class: Tar

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
ext/tarruby.c

Defined Under Namespace

Classes: Error

Constant Summary collapse

VERSION =
rb_str_new2(VERSION)
GNU =

use GNU extensions

INT2NUM(TAR_GNU)
VERBOSE =

output file info to stdout

INT2NUM(TAR_VERBOSE)
NOOVERWRITE =

don’t overwrite existing files

INT2NUM(TAR_NOOVERWRITE)
IGNORE_EOT =

ignore double zero blocks as EOF

INT2NUM(TAR_IGNORE_EOT)
CHECK_MAGIC =

check magic in file header

INT2NUM(TAR_CHECK_MAGIC)
CHECK_VERSION =

check version in file header

INT2NUM(TAR_CHECK_VERSION)
IGNORE_CRC =

ignore CRC in file header

INT2NUM(TAR_IGNORE_CRC)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.bzopen(*args) ⇒ Object



242
243
244
# File 'ext/tarruby.c', line 242

static VALUE tarruby_s_bzopen(int argc, VALUE *argv, VALUE self) {
  return tarruby_s_open0(argc, argv, self, &bztype);
}

.gzopen(*args) ⇒ Object



235
236
237
# File 'ext/tarruby.c', line 235

static VALUE tarruby_s_gzopen(int argc, VALUE *argv, VALUE self) {
  return tarruby_s_open0(argc, argv, self, &gztype);
}

.open(*args) ⇒ Object

ignore CRC in file header



229
230
231
# File 'ext/tarruby.c', line 229

static VALUE tarruby_s_open(int argc, VALUE *argv, VALUE self) {
  return tarruby_s_open0(argc, argv, self, NULL);
}

Instance Method Details

#append_file(*args) ⇒ Object



248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
# File 'ext/tarruby.c', line 248

static VALUE tarruby_append_file(int argc, VALUE *argv, VALUE self) {
  VALUE realname, savename;
  struct tarruby_tar *p_tar;
  char *s_realname, *s_savename = NULL;

  rb_scan_args(argc, argv, "11", &realname, &savename);
  Check_Type(realname, T_STRING);
  s_realname = RSTRING_PTR(realname);
  strip_sep(s_realname);

  if (!NIL_P(savename)) {
    Check_Type(savename, T_STRING);
    s_savename = RSTRING_PTR(savename);
    strip_sep(s_savename);
  }

  Data_Get_Struct(self, struct tarruby_tar, p_tar);

  if (tar_append_file(p_tar->tar, s_realname, s_savename) != 0) {
    rb_raise(Error, "Append file failed: %s", strerror(errno));
  }

  return Qnil;
}

#append_tree(*args) ⇒ Object



274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
# File 'ext/tarruby.c', line 274

static VALUE tarruby_append_tree(int argc, VALUE *argv, VALUE self) {
  VALUE realdir, savedir;
  struct tarruby_tar *p_tar;
  char *s_realdir, *s_savedir = NULL;

  rb_scan_args(argc, argv, "11", &realdir, &savedir);
  Check_Type(realdir, T_STRING);
  s_realdir = RSTRING_PTR(realdir);
  strip_sep(s_realdir);

  if (!NIL_P(savedir)) {
    Check_Type(savedir, T_STRING);
    s_savedir = RSTRING_PTR(savedir);
    strip_sep(s_savedir);
  }

  Data_Get_Struct(self, struct tarruby_tar, p_tar);

  if (tar_append_tree(p_tar->tar, s_realdir, s_savedir) != 0) {
    rb_raise(Error, "Append tree failed: %s", strerror(errno));
  }

  return Qnil;
}

#blk?Boolean

Returns:

  • (Boolean)


566
567
568
569
570
571
572
# File 'ext/tarruby.c', line 566

static VALUE tarruby_is_blk(VALUE self) {
  struct tarruby_tar *p_tar;

  Data_Get_Struct(self, struct tarruby_tar, p_tar);

  return TH_ISBLK(p_tar->tar) ? Qtrue : Qfalse;
}

#chr?Boolean

Returns:

  • (Boolean)


557
558
559
560
561
562
563
# File 'ext/tarruby.c', line 557

static VALUE tarruby_is_chr(VALUE self) {
  struct tarruby_tar *p_tar;

  Data_Get_Struct(self, struct tarruby_tar, p_tar);

  return TH_ISCHR(p_tar->tar) ? Qtrue : Qfalse;
}

#closeObject



187
188
189
# File 'ext/tarruby.c', line 187

static VALUE tarruby_close(VALUE self) {
  return tarruby_close0(self, 1);
}

#crcObject



440
441
442
443
444
# File 'ext/tarruby.c', line 440

static VALUE tarruby_crc(VALUE self) {
  struct tarruby_tar *p_tar;
  Data_Get_Struct(self, struct tarruby_tar, p_tar);
  return INT2NUM(th_get_crc(p_tar->tar));
}

#devmajorObject



461
462
463
464
465
# File 'ext/tarruby.c', line 461

static VALUE tarruby_devmajor(VALUE self) {
  struct tarruby_tar *p_tar;
  Data_Get_Struct(self, struct tarruby_tar, p_tar);
  return INT2NUM(th_get_devmajor(p_tar->tar));
}

#devminorObject



468
469
470
471
472
# File 'ext/tarruby.c', line 468

static VALUE tarruby_devminor(VALUE self) {
  struct tarruby_tar *p_tar;
  Data_Get_Struct(self, struct tarruby_tar, p_tar);
  return INT2NUM(th_get_devminor(p_tar->tar));
}

#dir?Boolean

Returns:

  • (Boolean)


575
576
577
578
579
580
581
# File 'ext/tarruby.c', line 575

static VALUE tarruby_is_dir(VALUE self) {
  struct tarruby_tar *p_tar;

  Data_Get_Struct(self, struct tarruby_tar, p_tar);

  return TH_ISDIR(p_tar->tar) ? Qtrue : Qfalse;
}

#eachObject



419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
# File 'ext/tarruby.c', line 419

static VALUE tarruby_each(VALUE self) {
  struct tarruby_tar *p_tar;
  int i;

  Data_Get_Struct(self, struct tarruby_tar, p_tar);
  tarruby_skip_regfile_if_not_extracted(p_tar);

  while ((i = th_read(p_tar->tar)) == 0) {
    p_tar->extracted = 0;
    rb_yield(self);
    tarruby_skip_regfile_if_not_extracted(p_tar);
  }

  if (i == -1) {
    rb_raise(Error, "Read archive failed: %s", strerror(errno));
  }

  return Qnil;
}

#extract_all(*args) ⇒ Object



368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
# File 'ext/tarruby.c', line 368

static VALUE tarruby_extract_all(int argc, VALUE *argv, VALUE self) {
  VALUE prefix;
  struct tarruby_tar *p_tar;
  char *s_prefix = NULL;

  rb_scan_args(argc, argv, "01", &prefix);

  if (!NIL_P(prefix)) {
    Check_Type(prefix, T_STRING);
    s_prefix = RSTRING_PTR(prefix);
  }

  Data_Get_Struct(self, struct tarruby_tar, p_tar);

  if (tar_extract_all(p_tar->tar, s_prefix) != 0) {
    rb_raise(Error, "Extract archive failed: %s", strerror(errno));
  }

  p_tar->extracted = 1;

  return Qnil;
}

#extract_bufferObject



324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
# File 'ext/tarruby.c', line 324

static VALUE tarruby_extract_buffer(VALUE self) {
  VALUE buffer;
  struct tarruby_tar *p_tar;
  int i;

  Data_Get_Struct(self, struct tarruby_tar, p_tar);
  buffer = rb_str_new("", 0);

  if ((i = tar_extract_function(p_tar->tar, (void *) buffer,  tarruby_extract_buffer0)) == -1) {
    rb_raise(Error, "Extract buffer failed: %s", strerror(errno));
  }

  p_tar->extracted = 1;

  return (i == 0) ? buffer : Qnil;
}

#extract_file(realname) ⇒ Object



300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
# File 'ext/tarruby.c', line 300

static VALUE tarruby_extract_file(VALUE self, VALUE realname) {
  struct tarruby_tar *p_tar;
  char *s_realname;

  Check_Type(realname, T_STRING);
  s_realname = RSTRING_PTR(realname);
  Data_Get_Struct(self, struct tarruby_tar, p_tar);

  if (tar_extract_file(p_tar->tar, s_realname) != 0) {
    rb_raise(Error, "Extract file failed: %s", strerror(errno));
  }

  p_tar->extracted = 1;

  return Qnil;
}

#extract_glob(*args) ⇒ Object



342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
# File 'ext/tarruby.c', line 342

static VALUE tarruby_extract_glob(int argc, VALUE *argv, VALUE self) {
  VALUE globname, prefix;
  struct tarruby_tar *p_tar;
  char *s_globname, *s_prefix = NULL;

  rb_scan_args(argc, argv, "11", &globname, &prefix);
  Check_Type(globname, T_STRING);
  s_globname = RSTRING_PTR(globname);

  if (!NIL_P(prefix)) {
    Check_Type(prefix, T_STRING);
    s_prefix = RSTRING_PTR(prefix);
  }

  Data_Get_Struct(self, struct tarruby_tar, p_tar);

  if (tar_extract_glob(p_tar->tar, s_globname, s_prefix) != 0) {
    rb_raise(Error, "Extract archive failed: %s", strerror(errno));
  }

  p_tar->extracted = 1;

  return Qnil;
}

#fifo?Boolean

Returns:

  • (Boolean)


584
585
586
587
588
589
590
# File 'ext/tarruby.c', line 584

static VALUE tarruby_is_fifo(VALUE self) {
  struct tarruby_tar *p_tar;

  Data_Get_Struct(self, struct tarruby_tar, p_tar);

  return TH_ISFIFO(p_tar->tar) ? Qtrue : Qfalse;
}

#gidObject



503
504
505
506
507
# File 'ext/tarruby.c', line 503

static VALUE tarruby_gid(VALUE self) {
  struct tarruby_tar *p_tar;
  Data_Get_Struct(self, struct tarruby_tar, p_tar);
  return LONG2NUM(th_get_gid(p_tar->tar));
}

#linknameObject



475
476
477
478
479
# File 'ext/tarruby.c', line 475

static VALUE tarruby_linkname(VALUE self) {
  struct tarruby_tar *p_tar;
  Data_Get_Struct(self, struct tarruby_tar, p_tar);
  return rb_str_new2(th_get_linkname(p_tar->tar));
}

#lnk?Boolean

Returns:

  • (Boolean)


539
540
541
542
543
544
545
# File 'ext/tarruby.c', line 539

static VALUE tarruby_is_lnk(VALUE self) {
  struct tarruby_tar *p_tar;

  Data_Get_Struct(self, struct tarruby_tar, p_tar);

  return TH_ISLNK(p_tar->tar) ? Qtrue : Qfalse;
}

#longlink?Boolean

Returns:

  • (Boolean)


602
603
604
605
606
607
608
# File 'ext/tarruby.c', line 602

static VALUE tarruby_is_longlink(VALUE self) {
  struct tarruby_tar *p_tar;

  Data_Get_Struct(self, struct tarruby_tar, p_tar);

  return TH_ISLONGLINK(p_tar->tar) ? Qtrue : Qfalse;
}

#longname?Boolean

Returns:

  • (Boolean)


593
594
595
596
597
598
599
# File 'ext/tarruby.c', line 593

static VALUE tarruby_is_longname(VALUE self) {
  struct tarruby_tar *p_tar;

  Data_Get_Struct(self, struct tarruby_tar, p_tar);

  return TH_ISLONGNAME(p_tar->tar) ? Qtrue : Qfalse;
}

#modeObject



489
490
491
492
493
# File 'ext/tarruby.c', line 489

static VALUE tarruby_mode(VALUE self) {
  struct tarruby_tar *p_tar;
  Data_Get_Struct(self, struct tarruby_tar, p_tar);
  return LONG2NUM(th_get_mode(p_tar->tar));
}

#mtimeObject



454
455
456
457
458
# File 'ext/tarruby.c', line 454

static VALUE tarruby_mtime(VALUE self) {
  struct tarruby_tar *p_tar;
  Data_Get_Struct(self, struct tarruby_tar, p_tar);
  return INT2TIME(th_get_mtime(p_tar->tar));
}

#pathnameObject



482
483
484
485
486
# File 'ext/tarruby.c', line 482

static VALUE tarruby_pathname(VALUE self) {
  struct tarruby_tar *p_tar;
  Data_Get_Struct(self, struct tarruby_tar, p_tar);
  return rb_str_new2(th_get_pathname(p_tar->tar));
}


510
511
512
513
514
515
516
517
# File 'ext/tarruby.c', line 510

static VALUE tarruby_print(VALUE self) {
  struct tarruby_tar *p_tar;

  Data_Get_Struct(self, struct tarruby_tar, p_tar);
  th_print(p_tar->tar);

  return Qnil;
}


520
521
522
523
524
525
526
527
# File 'ext/tarruby.c', line 520

static VALUE tarruby_print_long_ls(VALUE self) {
  struct tarruby_tar *p_tar;

  Data_Get_Struct(self, struct tarruby_tar, p_tar);
  th_print_long_ls(p_tar->tar);

  return Qnil;
}

#readObject



402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
# File 'ext/tarruby.c', line 402

static VALUE tarruby_read(VALUE self) {
  struct tarruby_tar *p_tar;
  int i;

  Data_Get_Struct(self, struct tarruby_tar, p_tar);
  tarruby_skip_regfile_if_not_extracted(p_tar);

  if ((i = th_read(p_tar->tar)) == -1) {
    rb_raise(Error, "Read archive failed: %s", strerror(errno));
  }

  p_tar->extracted = 0;

  return (i == 0) ? Qtrue : Qfalse;
}

#reg?Boolean

Returns:

  • (Boolean)


530
531
532
533
534
535
536
# File 'ext/tarruby.c', line 530

static VALUE tarruby_is_reg(VALUE self) {
  struct tarruby_tar *p_tar;

  Data_Get_Struct(self, struct tarruby_tar, p_tar);

  return TH_ISREG(p_tar->tar) ? Qtrue : Qfalse;
}

#sizeObject



447
448
449
450
451
# File 'ext/tarruby.c', line 447

static VALUE tarruby_size(VALUE self) {
  struct tarruby_tar *p_tar;
  Data_Get_Struct(self, struct tarruby_tar, p_tar);
  return INT2NUM(th_get_size(p_tar->tar));
}

#sym?Boolean

Returns:

  • (Boolean)


548
549
550
551
552
553
554
# File 'ext/tarruby.c', line 548

static VALUE tarruby_is_sym(VALUE self) {
  struct tarruby_tar *p_tar;

  Data_Get_Struct(self, struct tarruby_tar, p_tar);

  return TH_ISSYM(p_tar->tar) ? Qtrue : Qfalse;
}

#uidObject



496
497
498
499
500
# File 'ext/tarruby.c', line 496

static VALUE tarruby_uid(VALUE self) {
  struct tarruby_tar *p_tar;
  Data_Get_Struct(self, struct tarruby_tar, p_tar);
  return LONG2NUM(th_get_uid(p_tar->tar));
}