]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Copyright (c) 2001, Robert Collins. | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify | |
5 | * it under the terms of the GNU General Public License as published by | |
6 | * the Free Software Foundation; either version 2 of the License, or | |
7 | * (at your option) any later version. | |
8 | * | |
9 | * A copy of the GNU General Public License can be found at | |
10 | * http://www.gnu.org/ | |
11 | * | |
12 | * Written by Robert Collins <rbtcollins@hotmail.com> | |
13 | * | |
14 | */ | |
15 | ||
16 | #include "compress.h" | |
17 | #include "compress_gz.h" | |
18 | #include "compress_bz.h" | |
19 | ||
20 | /* In case you are wondering why the file magic is not in one place: | |
21 | * It could be. But there is little (any?) benefit. | |
22 | * What is important is that the file magic required for any _task_ is centralised. | |
23 | * One such task is identifying compresss | |
24 | * | |
25 | * to federate into each class one might add a magic parameter to the constructor, which | |
26 | * the class could test itself. | |
27 | */ | |
28 | ||
29 | #define longest_magic 3 | |
30 | ||
31 | io_stream * | |
32 | compress::decompress (io_stream * original) | |
33 | { | |
34 | if (!original) | |
35 | return NULL; | |
36 | char magic[longest_magic]; | |
37 | if (original->peek (magic, longest_magic) > 0) | |
38 | { | |
39 | if (memcmp (magic, "\037\213", 2) == 0) | |
40 | { | |
41 | /* tar */ | |
42 | compress_gz *rv = new compress_gz (original); | |
43 | if (!rv->error ()) | |
44 | return rv; | |
45 | return NULL; | |
46 | } | |
47 | else if (memcmp (magic, "BZh", 3) == 0) | |
48 | { | |
49 | compress_bz *rv = new compress_bz (original); | |
50 | if (!rv->error ()) | |
51 | return rv; | |
52 | return NULL; | |
53 | } | |
54 | } | |
55 | return NULL; | |
56 | } | |
57 | ||
58 | compress::~compress () {} |