summaryrefslogtreecommitdiffstats
path: root/design.txt
blob: 9fc1879d7d16ad80a868d0e8733343f4325fe183 (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
51
52
53
54
55
56
file_read(user_data, buffer, *size)
	file = user_data
	*size = fread(buffer, 1, *size, file)

extract(file_name, outer_member, inner_action)
	FILE *file = fopen(file_name, "rb")
	outer_gzip  = gzip_init(&file_read, file)
	outer_ustar = ustar_init(outer_gzip)
	ustar_seek(outer_ustar, outer_member)
	inner_gzip  = gzip_init(&ustar_read, outer_ustar)
	inner_ustar = ustar_init(inner_gzip)
	inner_action(inner_ustar)

read_control(inner_ustar)
	unsigned char buffer[512]
	size
	ustar_seek(inner_ustar, "control")
	while ((ret = ustar_read(inner_ustar, buffer, &size)) == OK)
		fwrite(buffer, 1 size, stdout)
	if ret == ERROR
		return

list_members(inner_ustar)
	ustar_member member
	while ((ret = ustar_list(inner_ustar, &member)) == OK)
		printf("%s", member.name)
	if ret == ERROR
		return

main()
	if -I
		extract(argv[1], "control.tar.gz", &read_control)
	else if -c
		extract(argv[1], "data.tar.gz", &list_members)

---

struct gzip *
gzip_init(int (*read)(void *, char *, size_t *), void *user_data)

int
gzip_read(struct gzip *gzip, void *record)

---

struct ustar *
ustar_init(struct gzip *gzip)

int
ustar_list(struct ustar *ustar, ustar_member *member)

int
ustar_seek(ustruct star *ustar, const char *member)

int
ustar_read(struct ustar *ustar, char *buffer, size_t *size)