// Read up to N bytes for analyze the magic
#define MAX_MAGIC_LENGTH 6
+// Compression/Decompression buffer size
+#define BUFFER_SIZE 64 * 1024
+
const struct compressor {
char magic[MAX_MAGIC_LENGTH];
size_t magic_length;
{ "", 0, NULL, },
};
-struct xz_cookie {
- FILE* f;
- lzma_stream stream;
- int done;
-
- uint8_t buffer[64 * 1024];
-};
-
// Try to guess the compression
FILE* pakfire_xfopen(FILE* f, const char* mode) {
char buffer[MAX_MAGIC_LENGTH];
return f;
}
+struct xz_cookie {
+ FILE* f;
+ char mode;
+ lzma_stream stream;
+ int done;
+
+ uint8_t buffer[BUFFER_SIZE];
+};
+
+
static ssize_t xz_read(void* data, char* buffer, size_t size) {
struct xz_cookie* cookie = (struct xz_cookie*)data;
if (!cookie)
if (cookie->stream.avail_in == 0) {
cookie->stream.next_in = cookie->buffer;
cookie->stream.avail_in = fread(cookie->buffer,
- 1, sizeof(*cookie->buffer), cookie->f);
+ 1, sizeof(cookie->buffer), cookie->f);
// Break if the input file could not be read
if (ferror(cookie->f))