]>
Commit | Line | Data |
---|---|---|
b24c88b3 RC |
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 | /* Archive IO operations | |
17 | */ | |
18 | ||
19 | #if 0 | |
20 | static const char *cvsid = | |
21 | "\n%%% $Id$\n"; | |
22 | #endif | |
23 | ||
24 | #include "win32.h" | |
25 | #include <stdio.h> | |
26 | #include "log.h" | |
27 | #include "port.h" | |
28 | ||
29 | #include "io_stream.h" | |
30 | #include "compress.h" | |
31 | #include "zlib/zlib.h" | |
32 | #include "compress_gz.h" | |
33 | #include "compress_bz.h" | |
34 | ||
35 | /* In case you are wondering why the file magic is not in one place: | |
36 | * It could be. But there is little (any?) benefit. | |
37 | * What is important is that the file magic required for any _task_ is centralised. | |
38 | * One such task is identifying compresss | |
39 | * | |
40 | * to federate into each class one might add a magic parameter to the constructor, which | |
41 | * the class could test itself. | |
42 | */ | |
43 | ||
44 | #define longest_magic 3 | |
45 | ||
46 | io_stream * | |
47 | compress::decompress (io_stream * original) | |
48 | { | |
49 | if (!original) | |
50 | return NULL; | |
51 | char magic[longest_magic]; | |
52 | if (original->peek (magic, longest_magic) > 0) | |
53 | { | |
54 | if (memcmp (magic, "\037\213", 2) == 0) | |
55 | { | |
56 | /* tar */ | |
57 | compress_gz *rv = new compress_gz (original); | |
58 | if (!rv->error ()) | |
59 | return rv; | |
60 | return NULL; | |
61 | } | |
62 | else if (memcmp (magic, "BZh", 3) == 0) | |
63 | { | |
64 | compress_bz *rv = new compress_bz (original); | |
65 | if (!rv->error ()) | |
66 | return rv; | |
67 | return NULL; | |
68 | } | |
69 | } | |
70 | return NULL; | |
71 | } | |
72 | ||
73 | ssize_t | |
74 | compress::read (void *buffer, size_t len) | |
75 | { | |
76 | log (LOG_TIMESTAMP, "compress::read called"); | |
77 | return 0; | |
78 | } | |
79 | ||
80 | ssize_t | |
81 | compress::write (void *buffer, size_t len) | |
82 | { | |
83 | log (LOG_TIMESTAMP, "compress::write called"); | |
84 | return 0; | |
85 | } | |
86 | ||
87 | ssize_t | |
88 | compress::peek (void *buffer, size_t len) | |
89 | { | |
90 | log (LOG_TIMESTAMP, "compress::peek called"); | |
91 | return 0; | |
92 | } | |
93 | ||
94 | long | |
95 | compress::tell () | |
96 | { | |
97 | log (LOG_TIMESTAMP, "bz::tell called"); | |
98 | return 0; | |
99 | } | |
100 | ||
101 | int | |
102 | compress::error () | |
103 | { | |
104 | log (LOG_TIMESTAMP, "compress::error called"); | |
105 | return 0; | |
106 | } | |
107 | ||
108 | const char * | |
109 | compress::next_file_name () | |
110 | { | |
111 | log (LOG_TIMESTAMP, "compress::next_file_name called"); | |
112 | return NULL; | |
113 | } | |
114 | ||
115 | compress::~compress () | |
116 | { | |
e9440f0f | 117 | log (LOG_BABBLE, "compress::~compress called"); |
b24c88b3 RC |
118 | return; |
119 | } |