summaryrefslogtreecommitdiffstats
path: root/Utilities/cmlibarchive/examples/minitar/notes
blob: 79728d4e5e25e3016d781841c6cd6488cb02e941 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
create(const char* filename)
{
  struct archive *a;
  a = archive_write_new();
// pick a compression type
  archive_write_set_compression_bzip2(a);
  archive_write_set_compression_compress(a);
  archive_write_set_compression_gzip(a);
  archive_write_set_compression_none(a);
  
// what does this do???
  archive_write_set_format_ustar(a); // is this what we want?
// maybe this:
  archive_write_set_format_pax(a);

  archive_write_open_file(a, filename);

  struct archive* disk = archive_read_disk_new();
  archive_read_disk_set_standard_lookup(disk);
  while (*argv != NULL)
    {
    struct tree *t = tree_open(*argv);
    while (tree_next(t)) 
      { 
      entry = archive_entry_new();
      archive_entry_set_pathname(entry, tree_current_path(t));
      archive_read_disk_entry_from_file(disk, entry, -1,
                                        tree_current_stat(t));
      if (verbose)
        {
        msg("a ");
        msg(tree_current_path(t));
        }
      archive_write_header(a, entry);
      int fd = open(tree_current_access_path(t), O_RDONLY);
      char buff[16384];
      len = read(fd, buff, sizeof(buff));
      while (len > 0)
        {
        archive_write_data(a, buff, len);
        len = read(fd, buff, sizeof(buff));
        }
      close(fd);
      archive_entry_free(entry);
      if (verbose)
        msg("\n");
      }
      }
  
}