]> cygwin.com Git - cygwin-apps/setup.git/blame - compress.cc
2007-02-17 Brian Dessent <brian@dessent.net>
[cygwin-apps/setup.git] / compress.cc
CommitLineData
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
b24c88b3 16#include "compress.h"
b24c88b3
RC
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
31io_stream *
32compress::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
b16e07fc 58compress::~compress () {}
This page took 0.04103 seconds and 5 git commands to generate.