]> cygwin.com Git - cygwin-apps/setup.git/blob - compress.cc
Use solver to check for problems and produce a list of package transactions
[cygwin-apps/setup.git] / compress.cc
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 #include "compress_xz.h"
20 #include <string.h>
21
22 /* In case you are wondering why the file magic is not in one place:
23 * It could be. But there is little (any?) benefit.
24 * What is important is that the file magic required for any _task_ is centralised.
25 * One such task is identifying compresss
26 *
27 * to federate into each class one might add a magic parameter to the constructor, which
28 * the class could test itself.
29 */
30
31 #define longest_magic 14 /* lzma_alone */
32
33 io_stream *
34 compress::decompress (io_stream * original)
35 {
36 if (!original)
37 return NULL;
38 char magic[longest_magic];
39 if (original->peek (magic, longest_magic) > 0)
40 {
41 if (memcmp (magic, "\037\213", 2) == 0)
42 {
43 /* tar */
44 compress_gz *rv = new compress_gz (original);
45 if (!rv->error ())
46 return rv;
47 /* else */
48 rv->release_original();
49 delete rv;
50 return NULL;
51 }
52 else if (memcmp (magic, "BZh", 3) == 0)
53 {
54 compress_bz *rv = new compress_bz (original);
55 if (!rv->error ())
56 return rv;
57 /* else */
58 rv->release_original();
59 delete rv;
60 return NULL;
61 }
62 else if (compress_xz::is_xz_or_lzma (magic, 14))
63 {
64 compress_xz *rv = new compress_xz (original);
65 if (!rv->error ())
66 return rv;
67 /* else */
68 rv->release_original();
69 delete rv;
70 return NULL;
71 }
72 }
73 return NULL;
74 }
75
76 compress::~compress () {}
This page took 0.041911 seconds and 5 git commands to generate.