Fix MD5sum.str () formatting bug
[cygwin-setup.git] / compress_xz.h
blob07572ef2f19a9d78e387ea72e0726243779b37e3
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 /* this is the parent class for all compress IO operations.
22 #include "compress.h"
23 #include <lzma.h>
25 class compress_xz:public compress
27 public:
28 compress_xz (io_stream *); /* decompress (read) only */
29 virtual ssize_t read (void *buffer, size_t len);
30 virtual ssize_t write (const void *buffer, size_t len); /* not implemented */
31 virtual ssize_t peek (void *buffer, size_t len);
32 virtual long tell (); /* not implemented */
33 virtual int seek (long where, io_stream_seek_t whence); /* not implemented */
34 virtual int error ();
35 virtual const char *next_file_name () { return NULL; };
36 virtual int set_mtime (time_t);
37 virtual time_t get_mtime ();
38 virtual mode_t get_mode ();
39 virtual size_t get_size () {return 0;};
40 virtual ~compress_xz ();
41 virtual void init_decoder (void);
42 static bool is_xz_or_lzma (void *buffer, size_t len);
43 static int bid_xz (void *buffer, size_t len);
44 static int bid_lzma (void *buffer, size_t len);
45 virtual void release_original(); /* give up ownership of original io_stream */
47 private:
48 compress_xz () {};
50 io_stream *original;
51 bool owns_original;
52 char peekbuf[512];
53 size_t peeklen;
54 int lasterr;
55 void destroy ();
57 struct private_data {
58 lzma_stream stream;
59 unsigned char *out_block;
60 size_t out_block_size;
61 uint64_t total_out;
62 char eof; /* True = found end of compressed data. */
63 unsigned char *in_block;
64 size_t in_block_size;
65 uint64_t total_in;
66 unsigned char *out_p;
67 size_t in_pos;
68 size_t out_pos;
69 size_t in_size;
70 size_t in_processed;
71 size_t out_processed;
74 typedef enum {
75 COMPRESSION_UNKNOWN = -1,
76 COMPRESSION_XZ,
77 COMPRESSION_LZMA
78 } compression_type_t;
80 compression_type_t compression_type;
82 static const size_t out_block_size = 64 * 1024;
83 static const size_t in_block_size = 64 * 1024;
84 struct private_data *state;
87 #endif /* SETUP_COMPRESS_XZ_H */