-
Notifications
You must be signed in to change notification settings - Fork 1
/
DiskWriter.xs
74 lines (56 loc) · 1.46 KB
/
DiskWriter.xs
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
MODULE = Archive::Raw PACKAGE = Archive::Raw::DiskWriter
DiskWriter
new (class, flags)
SV *class
int flags
PREINIT:
archive_raw_diskwriter *self;
CODE:
Newxz (self, 1, archive_raw_diskwriter);
self->ar = archive_write_disk_new();
archive_write_disk_set_options (self->ar, flags);
archive_write_disk_set_standard_lookup (self->ar);
if (self->ar == NULL)
croak ("archive_write_disk_new() failed");
RETVAL = self;
OUTPUT: RETVAL
void
write (self, entry)
DiskWriter self
Entry entry
PREINIT:
int rc;
CODE:
rc = archive_write_header (self->ar, entry->e);
archive_check_error (rc, self->ar, archive_write_header);
if (archive_entry_size (entry->e) > 0)
{
const void *buffer;
size_t size;
la_int64_t offset;
for (;;)
{
rc = archive_read_data_block (entry->reader->ar, &buffer, &size, &offset);
if (rc == ARCHIVE_EOF)
break;
archive_check_error (rc, entry->reader->ar, archive_read_data_block);
rc = archive_write_data_block (self->ar, buffer, size, offset);
archive_check_error (rc, self->ar, archive_write_data_block);
}
}
rc = archive_write_finish_entry (self->ar);
archive_check_error (rc, self->ar, archive_write_finish_entry);
void
close (self)
DiskWriter self
PREINIT:
int rc;
CODE:
rc = archive_write_close (self->ar);
archive_check_error (rc, self->ar, archive_write_close);
void
DESTROY (self)
DiskWriter self
CODE:
archive_write_free (self->ar);
Safefree (self);