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
12 * Written by Robert Collins <rbtcollins@hotmail.com>
17 #include "compress_gz.h"
18 #include "compress_bz.h"
19 #include "compress_xz.h"
20 #include "compress_zstd.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) */
35 compress::decompress (io_stream
* original
)
39 char magic
[longest_magic
];
40 if (original
->peek (magic
, longest_magic
) > 0)
42 if (memcmp (magic
, "\037\213", 2) == 0)
45 compress_gz
*rv
= new compress_gz (original
);
49 rv
->release_original();
53 else if (compress_zstd::is_zstd (magic
, 18))
55 compress_zstd
*rv
= new compress_zstd (original
);
59 rv
->release_original();
63 else if (memcmp (magic
, "BZh", 3) == 0)
65 compress_bz
*rv
= new compress_bz (original
);
69 rv
->release_original();
73 else if (compress_xz::is_xz_or_lzma (magic
, 14))
75 compress_xz
*rv
= new compress_xz (original
);
79 rv
->release_original();
87 compress::~compress () {}