--- ./Makefile.orig	2012-11-30 14:24:17.000000000 +0000
+++ ./Makefile	2012-11-30 14:28:13.000000000 +0000
@@ -5,8 +5,8 @@ mandir=$(prefix)/man
 rpmdumpheader=$(bindir)/rpmdumpheader
 zlibdir=zlib-1.2.2.f-rsyncable
 CFLAGS = -fPIC -O2 -Wall -g
-CPPFLAGS = -fPIC -DDELTARPM_64BIT -DBSDIFF_NO_SUF -DRPMDUMPHEADER=\"$(rpmdumpheader)\" -I$(zlibdir)
-LDLIBS = -lbz2 $(zlibdir)/libz.a -llzma
+CPPFLAGS = -fPIC -DDELTARPM_64BIT -DBSDIFF_NO_SUF -DRPMDUMPHEADER=\"$(rpmdumpheader)\" -I$(zlibdir) -Ilzmaalpha-utils/src/liblzma/api
+LDLIBS = -lbz2 $(zlibdir)/libz.a -llzma lzmaalpha-utils/liblzmaalpha.a
 LDFLAGS =
 PYTHONVERS = $(shell ls /usr/include/python*/Python.h | sed "s|/usr/include/||g"| sed "s|/Python.h||g")
 
@@ -33,8 +33,8 @@ _deltarpmmodule.so: readdeltarpm.o rpmhe
 	for ver in $(PYTHONVERS) ; do \
 		if [ ! -f "$$ver/$@" ]; then \
 			mkdir -p $$ver ;\
-			$(CC) $(CFLAGS) -I/usr/include/$$ver -I$(zlibdir) -fPIC -c -o $$ver/deltarpmmodule.o deltarpmmodule.c ;\
-			$(CC) -o $$ver/$@ $$ver/deltarpmmodule.o $^ -shared -Wl,-soname,_deltarpmmodule.so $(zlibdir)/libz.a -llzma -lbz2; \
+			$(CC) $(CFLAGS) -I/usr/include/$$ver $(CPPFLAGS) -c -o $$ver/deltarpmmodule.o deltarpmmodule.c ;\
+			$(CC) -o $$ver/$@ $$ver/deltarpmmodule.o $^ -shared -Wl,-soname,_deltarpmmodule.so $(LDLIBS); \
 		fi; \
 	done
 
--- ./cfile.c.orig	2012-11-30 13:55:20.000000000 +0000
+++ ./cfile.c	2012-11-30 14:22:27.000000000 +0000
@@ -13,6 +13,7 @@
 
 #include <zlib.h>
 #include <bzlib.h>
+#include <lzmaalpha.h>
 #include <lzma.h>
 
 #include "cfile.h"
@@ -650,12 +651,166 @@ crunread_gz(struct cfile *f, void *buf,
 
 
 /*****************************************************************
- *  lzma io
+ *  lzma (alpha) io
  */
 
 static struct cfile *
 cropen_lz(struct cfile *f)
 {
+  lzmaalpha_stream tmp = LZMAALPHA_STREAM_INIT_VAR;
+  f->strm.lza = tmp;
+  if (lzmaalpha_auto_decoder(&f->strm.lza, 0, 0) != LZMAALPHA_OK)
+    {
+      free(f);
+      return 0;
+    }
+  f->eof = 0;
+  f->strm.lza.avail_in = f->bufN == -1 ? 0 : f->bufN;
+  f->strm.lza.next_in  = (unsigned char *)f->buf;
+  return f;
+}
+
+static int
+crread_lz(struct cfile *f, void *buf, int len)
+{
+  int ret, used;
+  if (f->eof)
+    return 0;
+  f->strm.lza.avail_out = len;
+  f->strm.lza.next_out = buf;
+  for (;;)
+    {
+      if (f->strm.lza.avail_in == 0 && f->bufN)
+	{
+	  if (cfile_readbuf(f, f->buf, sizeof(f->buf)) == -1)
+	    return -1;
+	  f->strm.lza.avail_in = f->bufN;
+	  f->strm.lza.next_in = (unsigned char *)f->buf;
+	}
+      used = f->strm.lza.avail_in;
+      ret = lzmaalpha_code(&f->strm.lza, LZMAALPHA_RUN);
+      if (ret != LZMAALPHA_OK && ret != LZMAALPHA_STREAM_END)
+	return -1;
+      used -= f->strm.lza.avail_in;
+      if (used && f->ctxup)
+	f->ctxup(f->ctx, (unsigned char *)(f->strm.lza.next_in - used), used);
+      f->bytes += used;
+      if (ret == LZMAALPHA_STREAM_END)
+	{
+	  f->eof = 1;
+	  return len - f->strm.lza.avail_out;
+	}
+      if (f->strm.lza.avail_out == 0)
+	return len;
+      if (f->bufN == 0)
+	return -1;
+    }
+}
+
+static int
+crclose_lz(struct cfile *f)
+{
+  int r;
+  lzmaalpha_end(&f->strm.lza);
+  if (f->fd == CFILE_IO_CFILE && f->strm.lza.avail_in)
+    {
+      struct cfile *cf = (struct cfile *)f->fp;
+      if (cf->unread(cf, (void *)f->strm.lza.next_in, f->strm.lza.avail_in) != -1)
+        f->strm.lza.avail_in = 0;
+    }
+  r = (f->len != CFILE_LEN_UNLIMITED ? f->len : 0) + f->strm.lza.avail_in;
+  if (f->unreadbuf != f->buf)
+    free(f->unreadbuf);
+  free(f);
+  return r;
+}
+
+static struct cfile *
+cwopen_lz(struct cfile *f)
+{
+  lzmaalpha_options_alone alone;
+  lzmaalpha_stream tmp = LZMAALPHA_STREAM_INIT_VAR;
+
+  if (!f->level)
+    f->level = 3;
+  lzmaalpha_init_encoder();
+  f->strm.lza = tmp;
+  alone.uncompressed_size = LZMAALPHA_VLI_VALUE_UNKNOWN;
+  memcpy(&alone.lzma, &lzmaalpha_preset_lzma[f->level - 1], sizeof(alone.lzma));
+  if (lzmaalpha_alone_encoder(&f->strm.lza, &alone) != LZMAALPHA_OK)
+    {
+      free(f);
+      return 0;
+    }
+  return f;
+}
+
+static int
+cwclose_lz(struct cfile *f)
+{
+  int bytes, ret, n;
+  f->strm.lza.avail_in = 0;
+  f->strm.lza.next_in = 0;
+  for (;;)
+    {
+      f->strm.lza.avail_out = sizeof(f->buf);
+      f->strm.lza.next_out = (unsigned char *)f->buf;
+      ret = lzmaalpha_code(&f->strm.lza, LZMAALPHA_FINISH);
+      if (ret != LZMAALPHA_OK && ret != LZMAALPHA_STREAM_END)
+        return -1;
+      n = sizeof(f->buf) - f->strm.lza.avail_out;
+      if (n > 0)
+        if (cfile_writebuf(f, f->buf, n) != n)
+          return -1;
+      if (ret == LZMAALPHA_STREAM_END)
+        break;
+    }
+  lzmaalpha_end(&f->strm.lza);
+  if (f->fd == CFILE_IO_ALLOC)
+    cwclose_fixupalloc(f);
+  bytes = f->bytes;
+  free(f);
+  return bytes;
+}
+
+static int
+cwwrite_lz(struct cfile *f, void *buf, int len)
+{
+  int n, ret;
+
+  if (len <= 0)
+    return len < 0 ? -1 : 0;
+  f->strm.lza.avail_in = len;
+  f->strm.lza.next_in = buf;
+  for (;;)
+    {
+      f->strm.lza.avail_out = sizeof(f->buf);
+      f->strm.lza.next_out = (unsigned char *)f->buf;
+      ret = lzmaalpha_code(&f->strm.lza, LZMAALPHA_RUN);
+      if (ret != LZMA_OK)
+	return -1;
+      n = sizeof(f->buf) - f->strm.lza.avail_out;
+      if (n > 0)
+	if (cfile_writebuf(f, f->buf, n) != n)
+	  return -1;
+      if (f->strm.lza.avail_in == 0)
+	return len;
+    }
+}
+
+static int
+crunread_lz(struct cfile *f, void *buf, int len)
+{
+  return cfile_unreadbuf(f, buf, len, 0);
+}
+
+/*****************************************************************
+ *  xz io
+ */
+
+static struct cfile *
+cropen_xz(struct cfile *f)
+{
   lzma_stream tmp = LZMA_STREAM_INIT;
   f->strm.lz = tmp;
   if (lzma_auto_decoder(&f->strm.lz, 1 << 25, 0) != LZMA_OK)
@@ -670,7 +825,7 @@ cropen_lz(struct cfile *f)
 }
 
 static int
-crread_lz(struct cfile *f, void *buf, int len)
+crread_xz(struct cfile *f, void *buf, int len)
 {
   int ret, used;
   if (f->eof)
@@ -707,7 +862,7 @@ crread_lz(struct cfile *f, void *buf, in
 }
 
 static int
-crclose_lz(struct cfile *f)
+crclose_xz(struct cfile *f)
 {
   int r;
   lzma_end(&f->strm.lz);
@@ -725,24 +880,6 @@ crclose_lz(struct cfile *f)
 }
 
 static struct cfile *
-cwopen_lz(struct cfile *f)
-{
-  lzma_options_lzma alone;
-  lzma_stream tmp = LZMA_STREAM_INIT;
-
-  if (!f->level)
-    f->level = 2;
-  f->strm.lz = tmp;
-  lzma_lzma_preset(&alone, f->level);
-  if (lzma_alone_encoder(&f->strm.lz, &alone) != LZMA_OK)
-    {
-      free(f);
-      return 0;
-    }
-  return f;
-}
-
-static struct cfile *
 cwopen_xz(struct cfile *f)
 {
   lzma_stream tmp = LZMA_STREAM_INIT;
@@ -760,7 +897,7 @@ cwopen_xz(struct cfile *f)
 }
 
 static int
-cwclose_lz(struct cfile *f)
+cwclose_xz(struct cfile *f)
 {
   int bytes, ret, n;
   f->strm.lz.avail_in = 0;
@@ -788,7 +925,7 @@ cwclose_lz(struct cfile *f)
 }
 
 static int
-cwwrite_lz(struct cfile *f, void *buf, int len)
+cwwrite_xz(struct cfile *f, void *buf, int len)
 {
   int n, ret;
 
@@ -813,7 +950,7 @@ cwwrite_lz(struct cfile *f, void *buf, i
 }
 
 static int
-crunread_lz(struct cfile *f, void *buf, int len)
+crunread_xz(struct cfile *f, void *buf, int len)
 {
   return cfile_unreadbuf(f, buf, len, 0);
 }
@@ -1163,11 +1300,11 @@ cfile_open(int mode, int fd, void *fp, i
     case CFILE_COMP_XZ:
       f->strm.lz.allocator = 0;
       f->strm.lz.internal = 0;
-      f->read   = mode == CFILE_OPEN_RD ? crread_lz : 0;
-      f->unread = mode == CFILE_OPEN_RD ? crunread_lz : 0;
-      f->write  = mode == CFILE_OPEN_WR ? cwwrite_lz : 0;
-      f->close  = mode == CFILE_OPEN_RD ? crclose_lz : cwclose_lz;
-      return mode == CFILE_OPEN_RD ? cropen_lz(f) : cwopen_xz(f);
+      f->read   = mode == CFILE_OPEN_RD ? crread_xz : 0;
+      f->unread = mode == CFILE_OPEN_RD ? crunread_xz : 0;
+      f->write  = mode == CFILE_OPEN_WR ? cwwrite_xz : 0;
+      f->close  = mode == CFILE_OPEN_RD ? crclose_xz : cwclose_xz;
+      return mode == CFILE_OPEN_RD ? cropen_xz(f) : cwopen_xz(f);
     default:
       free(f);
       return 0;
--- ./cfile.h.orig	2012-11-30 13:55:24.000000000 +0000
+++ ./cfile.h	2012-11-30 14:20:42.000000000 +0000
@@ -8,6 +8,7 @@
 #include <zlib.h>
 #include <bzlib.h>
 #include <lzma.h>
+#include <lzmaalpha.h>
 
 struct cfile {
   int fd;
@@ -28,6 +29,7 @@ struct cfile {
   union {
     bz_stream bz;
     z_stream gz;
+    lzmaalpha_stream lza;
     lzma_stream lz;
   } strm;
   int (*read)(struct cfile *f, void *buf, int len);
