Add command-line option help-text localization
[cygwin-setup.git] / compress_xz.h
blob31d499c372a4d9a99b440e4500238b6f65a74de1
1 /*
2 * Copyright (c) 2010, Charles Wilson
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 Charles Wilson <cygwin@cygwin.com>
16 #ifndef SETUP_COMPRESS_XZ_H
17 #define SETUP_COMPRESS_XZ_H
19 #include "compress.h"
20 #include <lzma.h>
22 class compress_xz:public compress
24 public:
25 compress_xz (io_stream *); /* decompress (read) only */
26 virtual ssize_t read (void *buffer, size_t len);
27 virtual ssize_t write (const void *buffer, size_t len); /* not implemented */
28 virtual ssize_t peek (void *buffer, size_t len);
29 virtual long tell (); /* not implemented */
30 virtual int seek (long where, io_stream_seek_t whence);
31 virtual int error ();
32 virtual const char *next_file_name () { return NULL; };
33 virtual int set_mtime (time_t);
34 virtual time_t get_mtime ();
35 virtual mode_t get_mode ();
36 virtual size_t get_size () {return 0;};
37 virtual ~compress_xz ();
38 virtual void init_decoder (void);
39 static bool is_xz_or_lzma (void *buffer, size_t len);
40 static int bid_xz (void *buffer, size_t len);
41 static int bid_lzma (void *buffer, size_t len);
42 virtual void release_original(); /* give up ownership of original io_stream */
44 private:
45 compress_xz () {};
47 io_stream *original;
48 bool owns_original;
49 char peekbuf[512];
50 size_t peeklen;
51 int lasterr;
52 void create ();
53 void destroy ();
55 struct private_data {
56 lzma_stream stream;
57 unsigned char *out_block;
58 size_t out_block_size;
59 uint64_t total_out;
60 char eof; /* True = found end of compressed data. */
61 unsigned char *in_block;
62 size_t in_block_size;
63 uint64_t total_in;
64 unsigned char *out_p;
65 size_t in_pos;
66 size_t out_pos;
67 size_t in_size;
68 size_t in_processed;
69 size_t out_processed;
72 typedef enum {
73 COMPRESSION_UNKNOWN = -1,
74 COMPRESSION_XZ,
75 COMPRESSION_LZMA
76 } compression_type_t;
78 compression_type_t compression_type;
80 static const size_t out_block_size = 64 * 1024;
81 static const size_t in_block_size = 64 * 1024;
82 struct private_data *state;
85 #endif /* SETUP_COMPRESS_XZ_H */