Wire up de-DE and pl-PL translations
[cygwin-setup.git] / compress.cc
blob9ff41d385ac20d7ec7542de62d6daaaf8f247c20
1 /*
2 * Copyright (c) 2001, Robert Collins.
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.
9 * A copy of the GNU General Public License can be found at
10 * http://www.gnu.org/
12 * Written by Robert Collins <rbtcollins@hotmail.com>
16 #include "compress.h"
17 #include "compress_gz.h"
18 #include "compress_bz.h"
19 #include "compress_xz.h"
20 #include "compress_zstd.h"
21 #include <string.h>
23 /* In case you are wondering why the file magic is not in one place:
24 * It could be. But there is little (any?) benefit.
25 * What is important is that the file magic required for any _task_ is centralised.
26 * One such task is identifying compresss
28 * to federate into each class one might add a magic parameter to the constructor, which
29 * the class could test itself.
32 #define longest_magic 18 /* ZStandard longest frame header (magic is only 4 bytes) */
34 io_stream *
35 compress::decompress (io_stream * original)
37 if (!original)
38 return NULL;
39 char magic[longest_magic];
40 if (original->peek (magic, longest_magic) > 0)
42 if (memcmp (magic, "\037\213", 2) == 0)
44 /* tar */
45 compress_gz *rv = new compress_gz (original);
46 if (!rv->error ())
47 return rv;
48 /* else */
49 rv->release_original();
50 delete rv;
51 return NULL;
53 else if (compress_zstd::is_zstd (magic, 18))
55 compress_zstd *rv = new compress_zstd (original);
56 if (!rv->error ())
57 return rv;
58 /* else */
59 rv->release_original();
60 delete rv;
61 return NULL;
63 else if (memcmp (magic, "BZh", 3) == 0)
65 compress_bz *rv = new compress_bz (original);
66 if (!rv->error ())
67 return rv;
68 /* else */
69 rv->release_original();
70 delete rv;
71 return NULL;
73 else if (compress_xz::is_xz_or_lzma (magic, 14))
75 compress_xz *rv = new compress_xz (original);
76 if (!rv->error ())
77 return rv;
78 /* else */
79 rv->release_original();
80 delete rv;
81 return NULL;
84 return NULL;
87 compress::~compress () {}