diff -u dpkg-1.7.2/dpkg-deb/build.c dpkg-1.7.2.new/dpkg-deb/build.c
--- dpkg-1.7.2/dpkg-deb/build.c	Tue Aug 22 23:21:59 2000
+++ dpkg-1.7.2.new/dpkg-deb/build.c	Sun Dec  3 14:59:03 2000
@@ -139,6 +139,89 @@
   }
 }
 
+/* Functions to create the the deb archive. Must be called in the right order:
+ * 1. debar_open
+ * 2. debar_write_control_header
+ * 3. (copy gzipped control archive)
+ * 4. debar_write_data_header_newformat if !oldformat
+ * 5. (copy gzipped data archive)
+ * 6. debar_end_datafile_newformat if !oldformat
+ * 7. (close file)
+ */
+static FILE* debar_open(const char *debar) {
+  FILE *ar;
+  /* Now that we have verified everything its time to actually
+   * build something. Lets start by making the ar-wrapper.
+   */
+  if (!(ar=fopen(debar,"wb"))) ohshite(_("unable to create `%.255s'"),debar);
+  if (setvbuf(ar, 0, _IONBF, 0)) ohshite(_("unable to unbuffer `%.255s'"),debar);
+  return ar;
+}
+static void debar_write_control_header(FILE *ar, const char *debar, int oldformat,
+				       long control_size ) {
+  /* We have our first file for the ar-archive. Write a header for it to the
+   * package and insert it.
+   */
+  if (oldformatflag) {
+    if (fprintf(ar, "%-8s\n%ld\n", OLDARCHIVEVERSION, (long)control_size) == EOF)
+      werr(debar);
+  } else {
+    time_t thetime= time(0);
+    if (fprintf(ar,
+                "!<arch>\n"
+                "debian-binary   %-12lu0     0     100644  %-10ld`\n"
+                ARCHIVEVERSION "\n"
+                "%s"
+                ADMINMEMBER "%-12lu0     0     100644  %-10ld`\n",
+                thetime,
+                (long)sizeof(ARCHIVEVERSION),
+                (sizeof(ARCHIVEVERSION)&1) ? "\n" : "",
+                (unsigned long)thetime,
+                (long)control_size) == EOF)
+      werr(debar);
+  }                
+}
+static void debar_write_data_header_newformat(FILE *ar, const char *debar,
+					      long control_size, long data_size) {
+  time_t thetime= time(0);
+
+  if (fprintf(ar,
+              "%s"
+              DATAMEMBER "%-12lu0     0     100644  %-10ld`\n",
+              (control_size & 1) ? "\n" : "",
+              (unsigned long)thetime,
+              (long) data_size) == EOF)
+    werr(debar);
+}
+static void debar_end_datafile_newformat(FILE *ar, const char *debar, 
+	                                 long data_size) {
+  if (data_size & 1)
+    if (putc('\n',ar) == EOF)
+      werr(debar);
+}
+
+
+/* Create a new temporary file, unlink it immediately and return its fd.
+ * if file!=NULL, write handle of buffered stdio FILE there
+ */
+int open_tempfd(FILE **file) {
+  char *tfbuf, *envbuf;
+  int fd;
+
+  if ((envbuf= getenv("TMPDIR")) == NULL)
+    envbuf= (char *)P_tmpdir;
+  tfbuf = (char *)alloca(strlen(envbuf)+13);
+  strcpy(tfbuf,envbuf);
+  strcat(tfbuf,"/dpkg.XXXXXX");
+  if ((fd= mkstemp(tfbuf)) == -1) ohshite(_("failed to make tmpfile"));
+  if (file)
+    if ((*file= fdopen(fd,"a")) == NULL) ohshite(_("failed to open tmpfile "
+      "(control), %s"), tfbuf);
+  /* make sure it's gone, the fd will remain until we close it */
+  if (unlink(tfbuf)) ohshit(_("failed to unlink tmpfile, %s"), tfbuf);
+  return fd;
+}
+
 
 /* Overly complex function that builds a .deb file
  */
@@ -149,7 +232,7 @@
   
   char *m;
   const char *debar, *directory, *const *mscriptp, *versionstring, *arch;
-  char *controlfile, *tfbuf, *envbuf;
+  char *controlfile;
   struct pkginfo *checkedinfo;
   struct arbitraryfield *field;
   FILE *ar, *gz, *cf;
@@ -157,7 +240,6 @@
   pid_t c1,c2,c3,c4,c5;
   struct stat controlstab, datastab, mscriptstab, debarstab;
   char conffilename[MAXCONFFILENAME+1];
-  time_t thetime= 0;
   struct _finfo *fi;
   struct _finfo *nosymlist = NULL;
   struct _finfo *nosymlist_end = NULL;
@@ -166,12 +248,6 @@
   
 /* Decode our arguments */
   directory= *argv++; if (!directory) badusage(_("--build needs a directory argument"));
-  /* template for our tempfiles */
-  if ((envbuf= getenv("TMPDIR")) == NULL)
-    envbuf= (char *)P_tmpdir;
-  tfbuf = (char *)malloc(strlen(envbuf)+13);
-  strcpy(tfbuf,envbuf);
-  strcat(tfbuf,"/dpkg.XXXXXX");
   subdir= 0;
   if ((debar= *argv++) !=0) {
     if (*argv) badusage(_("--build takes at most two arguments"));
@@ -305,12 +381,8 @@
     }
   }
   if (ferror(stdout)) werr("stdout");
-  
-  /* Now that we have verified everything its time to actually
-   * build something. Lets start by making the ar-wrapper.
-   */
-  if (!(ar=fopen(debar,"wb"))) ohshite(_("unable to create `%.255s'"),debar);
-  if (setvbuf(ar, 0, _IONBF, 0)) ohshite(_("unable to unbuffer `%.255s'"),debar);
+
+  ar = debar_open(debar);
   /* Fork a tar to package the control-section of the package */
   m_pipe(p1);
   if (!(c1= m_fork())) {
@@ -320,18 +392,9 @@
     execlp(TAR,"tar","-cf","-",".",(char*)0); ohshite(_("failed to exec tar -cf"));
   }
   close(p1[1]);
-  /* Create a temporary file to store the control data in. Immediately unlink
-   * our temporary file so others can't mess with it.
+  /* Create a temporary file to store the control data in. 
    */
-  if ((gzfd= mkstemp(tfbuf)) == -1) ohshite(_("failed to make tmpfile (control)"));
-  if ((gz= fdopen(gzfd,"a")) == NULL) ohshite(_("failed to open tmpfile "
-      "(control), %s"), tfbuf);
-  /* make sure it's gone, the fd will remain until we close it */
-  if (unlink(tfbuf)) ohshit(_("failed to unlink tmpfile (control), %s"),
-      tfbuf);
-  /* reset this, so we can use it elsewhere */
-  strcpy(tfbuf,envbuf);
-  strcat(tfbuf,"/dpkg.XXXXXX");
+  gzfd= open_tempfd(&gz);
   /* And run gzip to compress our control archive */
   if (!(c2= m_fork())) {
     m_dup2(p1[0],0); m_dup2(gzfd,1); close(p1[0]); close(gzfd);
@@ -341,29 +404,9 @@
   waitsubproc(c2,"gzip -9c",0);
   waitsubproc(c1,"tar -cf",0);
   if (fstat(gzfd,&controlstab)) ohshite(_("failed to fstat tmpfile (control)"));
-  /* We have our first file for the ar-archive. Write a header for it to the
-   * package and insert it.
-   */
-  if (oldformatflag) {
-    if (fprintf(ar, "%-8s\n%ld\n", OLDARCHIVEVERSION, (long)controlstab.st_size) == EOF)
-      werr(debar);
-  } else {
-    thetime= time(0);
-    if (fprintf(ar,
-                "!<arch>\n"
-                "debian-binary   %-12lu0     0     100644  %-10ld`\n"
-                ARCHIVEVERSION "\n"
-                "%s"
-                ADMINMEMBER "%-12lu0     0     100644  %-10ld`\n",
-                thetime,
-                (long)sizeof(ARCHIVEVERSION),
-                (sizeof(ARCHIVEVERSION)&1) ? "\n" : "",
-                (unsigned long)thetime,
-                (long)controlstab.st_size) == EOF)
-      werr(debar);
-  }                
-                
+  debar_write_control_header(ar, debar, oldformatflag, controlstab.st_size);
   if (lseek(gzfd,0,SEEK_SET)) ohshite(_("failed to rewind tmpfile (control)"));
+
   do_fd_copy(gzfd, fileno(ar), _("control"));
 
   /* Control is done, now we need to archive the data. Start by creating
@@ -371,15 +414,7 @@
    * can't mess with it. */
   if (!oldformatflag) {
     fclose(gz);
-    if ((gzfd= mkstemp(tfbuf)) == -1) ohshite(_("failed to make tmpfile (data)"));
-    if ((gz= fdopen(gzfd,"a")) == NULL) ohshite(_("failed to open tmpfile "
-        "(data), %s"), tfbuf);
-    /* make sure it's gone, the fd will remain until we close it */
-    if (unlink(tfbuf)) ohshit(_("failed to unlink tmpfile (data), %s"),
-        tfbuf);
-    /* reset these, in case we want to use the later */
-    strcpy(tfbuf,envbuf);
-    strcat(tfbuf,"/dpkg.XXXXXX");
+    gzfd= open_tempfd(&gz);
   }
   /* We need to reorder the files so we can make sure that symlinks
    * will not appear before their target.
@@ -418,12 +453,12 @@
     char *combuf;
     close(p1[1]);
     m_dup2(p2[0],0); close(p2[0]);
-    m_dup2(oldformatflag ? fileno(ar) : gzfd,1);
+    m_dup2(oldformatflag?fileno(ar):gzfd,1);
     combuf = strdup("-9c");
     if(compression != NULL) {
       if(*compression == '0') {
-	do_fd_copy(0, 1, _("no compression copy loop"));
-	exit(0);
+        do_fd_copy(0, 1, _("no compression copy loop"));
+  	exit(0);
       }
       combuf[1] = *compression;
     }
@@ -447,27 +482,88 @@
   /* Okay, we have data.tar.gz as well now, add it to the ar wrapper */
   if (!oldformatflag) {
     if (fstat(gzfd,&datastab)) ohshite("_(failed to fstat tmpfile (data))");
-    if (fprintf(ar,
-                "%s"
-                DATAMEMBER "%-12lu0     0     100644  %-10ld`\n",
-                (controlstab.st_size & 1) ? "\n" : "",
-                (unsigned long)thetime,
-                (long)datastab.st_size) == EOF)
-      werr(debar);
-
+    debar_write_data_header_newformat(ar, debar, controlstab.st_size, 
+	    datastab.st_size);
     if (lseek(gzfd,0,SEEK_SET)) ohshite(_("failed to rewind tmpfile (data)"));
     if (!(c3= m_fork())) {
       m_dup2(gzfd,0); m_dup2(fileno(ar),1);
       execlp(CAT,"cat",(char*)0); ohshite(_("failed to exec cat (data)"));
     }
     waitsubproc(c3,"cat (data)",0);
-
-    if (datastab.st_size & 1)
-      if (putc('\n',ar) == EOF)
-        werr(debar);
+  
+    debar_end_datafile_newformat(ar, debar, datastab.st_size);
   }
+
   if (fclose(ar)) werr(debar);
-                             
+
   exit(0);
 }
 
+/* Compresses the given file and writes it to the given fd; returns
+ * the compressed size
+ */
+static long compress(const char *src, int dest) {
+  pid_t s;
+  struct stat statbuf;
+
+  if (!(s= m_fork())) {
+    m_dup2(dest,1); 
+    close(dest);
+    execlp(GZIP,"gzip","-c", src,(char*)0); ohshite(_("failed to exec gzip"));
+  }
+  waitsubproc(s,"gzip",0);
+
+  if (fstat(dest,&statbuf)) ohshite("_(failed to fstat compression dest)");    
+
+  if (lseek(dest,0,SEEK_SET)) ohshite(_("failed to rewind tmpfile"));  
+
+  return (long) statbuf.st_size;
+}
+
+
+void do_tarbuild(const char *const *argv) {
+  const char *debar;
+  const char *ctar;
+  const char *dtar;
+  FILE *ar;
+  int gzfd;
+  long ctarlen, dtarlen;
+  struct stat statbuf;
+
+  if (!(ctar=*argv++)) 
+    badusage(_("--tarbuild needs a control tar argument"));
+  if (!(dtar=*argv++)) 
+    badusage(_("--tarbuild needs a data tar argument"));
+  if (!(debar=*argv++)) 
+    badusage(_("--tarbuild needs a deb argument"));
+  if (*argv) 
+    badusage(_("--tarbuild takes exactly three arguments"));
+
+  if (stat(ctar,&statbuf) || (!S_ISREG(statbuf.st_mode))) 
+    ohshite(_("archive `%.250s' does not exist or is not a regular file"),
+	    ctar);
+  if (stat(dtar,&statbuf) || (!S_ISREG(statbuf.st_mode))) 
+    ohshite(_("archive `%.250s' does not exist or is not a regular file"),
+	    dtar);
+
+
+  gzfd = open_tempfd(NULL);
+
+  ar = debar_open(debar);
+
+  ctarlen = compress(ctar, gzfd);
+  debar_write_control_header(ar, debar, 0, ctarlen);
+  do_fd_copy(gzfd, fileno(ar), _("control"));
+
+  if (lseek(gzfd,0,SEEK_SET)) ohshite(_("failed to rewind tmpfile"));  
+
+  dtarlen = compress(dtar, gzfd);
+  debar_write_data_header_newformat(ar, debar, ctarlen, dtarlen);
+  do_fd_copy(gzfd, fileno(ar), _("data"));
+
+  debar_end_datafile_newformat(ar, debar, dtarlen);
+
+  if (fclose(ar)) werr(debar);
+  
+  exit(0);  
+}
diff -u dpkg-1.7.2/dpkg-deb/dpkg-deb.1 dpkg-1.7.2.new/dpkg-deb/dpkg-deb.1
--- dpkg-1.7.2/dpkg-deb/dpkg-deb.1	Sat Dec 25 04:21:47 1999
+++ dpkg-1.7.2.new/dpkg-deb/dpkg-deb.1	Mon Dec  4 22:43:13 2000
@@ -24,9 +24,15 @@
 .BR -x | --extract | -X | --vextract
 .I archive directory
 .br
+.B dpkg-deb --tar-build
+.I control-tar data-tar archive
+.br
 .B dpkg-deb --fsys-tarfile
 .I archive
 .br
+.B dpkg-deb --control-tarfile
+.I archive
+.br
 .B dpkg-deb --control
 .I archive directory
 .SH DESCRIPTION
@@ -161,6 +167,15 @@
 .I directory
 (but not its parents) will be created if necessary.
 .TP
+.BR --tar-build
+Creates a new debian archive from the control information files 
+.I control-tar
+and the filesystem tree
+.I data-tar. 
+Both are stored in 
+.B tar
+format.  
+.TP
 .BR --fsys-tarfile
 Extracts the filesystem tree data from a binary package and sends it
 to standard output in
@@ -168,6 +183,12 @@
 format.  Together with
 .B tar
 this can be used to extract a particular file from a package archive.
+.TP
+.BR --control-tarfile
+Extracts the control information files from a binary package and sends it
+to standard output in
+.B tar
+format.
 .TP
 .BR --control ", " -e
 Extracs the control information files from a package archive into the
diff -u dpkg-1.7.2/dpkg-deb/dpkg-deb.h dpkg-1.7.2.new/dpkg-deb/dpkg-deb.h
--- dpkg-1.7.2/dpkg-deb/dpkg-deb.h	Sun Nov  5 17:47:45 2000
+++ dpkg-1.7.2.new/dpkg-deb/dpkg-deb.h	Sun Dec  3 14:59:03 2000
@@ -24,7 +24,8 @@
 
 typedef void dofunction(const char *const *argv);
 dofunction do_build, do_contents, do_control;
-dofunction do_info, do_field, do_extract, do_vextract, do_fsystarfile;
+dofunction do_info, do_field, do_extract, do_vextract;
+dofunction do_tarbuild, do_fsystarfile, do_controltarfile;
 
 extern int debugflag, nocheckflag, oldformatflag;
 extern const struct cmdinfo *cipaction;
diff -u dpkg-1.7.2/dpkg-deb/extract.c dpkg-1.7.2.new/dpkg-deb/extract.c
--- dpkg-1.7.2/dpkg-deb/extract.c	Sun Oct 29 01:35:11 2000
+++ dpkg-1.7.2.new/dpkg-deb/extract.c	Sun Dec  3 14:59:03 2000
@@ -323,14 +323,22 @@
   extracthalf(debar, directory, taroptions, admin);
 }
 
-void do_fsystarfile(const char *const *argv) {
+void extract_tarfile(const char *const *argv, int admin) {
   const char *debar;
   
   if (!(debar= *argv++))
     badusage(_("--%s needs a .deb filename argument"),cipaction->olong);
   if (*argv)
     badusage(_("--%s takes only one argument (.deb filename)"),cipaction->olong);
-  extracthalf(debar,0,0,0);
+  extracthalf(debar,0,0,admin);
+}
+
+void do_fsystarfile(const char *const *argv) {
+  extract_tarfile(argv, 0);
+}
+
+void do_controltarfile(const char *const *argv) {
+  extract_tarfile(argv, 1);
 }
    
 void do_control(const char *const *argv) { controlextractvextract(1, "x", argv); }
Only in dpkg-1.7.2.new/dpkg-deb: index.bt
diff -u dpkg-1.7.2/dpkg-deb/main.c dpkg-1.7.2.new/dpkg-deb/main.c
--- dpkg-1.7.2/dpkg-deb/main.c	Sun Nov  5 17:47:45 2000
+++ dpkg-1.7.2.new/dpkg-deb/main.c	Sun Dec  3 14:59:03 2000
@@ -60,12 +60,16 @@
        dpkg-deb -e|--control <deb> [<directory>]  Extract control info.\n\
        dpkg-deb -x|--extract <deb> <directory>    Extract files.\n\
        dpkg-deb -X|--vextract <deb> <directory>   Extract & list files.\n\
+       dpkg-deb --tar-build <ctar> <dtar> <deb>   Build archive from tars.\n\
        dpkg-deb --fsys-tarfile <deb>              Output filesystem tarfile.\n\
+       dpkg-deb --control-tarfile <deb>           Output control tarfile.\n\
        dpkg-deb -h|--help                         Display this message.\n\
        dpkg-deb --version | --licence             Show version/licence.\n\
 <deb> is the filename of a Debian format archive.\n\
 <cfile> is the name of an administrative file component.\n\
 <cfield> is the name of a field in the main `control' file.\n\
+<ctar> is the name of an uncompressed control.tar file.\n\
+<dtar> is the name of an uncompressed data.tar file.\n\
 Options:  -D for debugging output; --old or --new controls archive format;\n\
           --nocheck to suppress control file check (build bad package).\n\
           -z# to set the compression when building\n\
@@ -103,31 +107,35 @@
   do_field,
   do_extract,
   do_vextract,
-  do_fsystarfile
+  do_tarbuild,
+  do_fsystarfile,
+  do_controltarfile
 };
 
 /* NB: the entries using setaction must appear first and be in the
  * same order as dofunctions:
  */
 static const struct cmdinfo cmdinfos[]= {
-  { "build",        'b',  0,  0, 0,               setaction        },
-  { "contents",     'c',  0,  0, 0,               setaction        },
-  { "control",      'e',  0,  0, 0,               setaction        },
-  { "info",         'I',  0,  0, 0,               setaction        },
-  { "field",        'f',  0,  0, 0,               setaction        },
-  { "extract",      'x',  0,  0, 0,               setaction        },
-  { "vextract",     'X',  0,  0, 0,               setaction        },
-  { "fsys-tarfile",  0,   0,  0, 0,               setaction        },
-  { "new",           0,   0,  &oldformatflag, 0,  0,            0  },
-  { "old",           0,   0,  &oldformatflag, 0,  0,            1  },
-  { "debug",        'D',  0,  &debugflag,     0,  0,            1  },
-  { "nocheck",       0,   0,  &nocheckflag,   0,  0,            1  },
-  { "compression",  'z',  1,  0,   &compression,  0,            1  },
-  { "help",         'h',  0,  0, 0,               helponly         },
-  { "version",       0,   0,  0, 0,               versiononly      },
-  { "licence",       0,   0,  0, 0,               showcopyright    }, /* UK spelling */
-  { "license",       0,   0,  0, 0,               showcopyright    }, /* US spelling */
-  {  0,              0                                             }
+  { "build",         'b',  0,  0, 0,               setaction        },
+  { "contents",      'c',  0,  0, 0,               setaction        },
+  { "control",       'e',  0,  0, 0,               setaction        },
+  { "info",          'I',  0,  0, 0,               setaction        },
+  { "field",         'f',  0,  0, 0,               setaction        },
+  { "extract",       'x',  0,  0, 0,               setaction        },
+  { "vextract",      'X',  0,  0, 0,               setaction        },
+  { "tar-build",      0,   0,  0, 0,               setaction        },
+  { "fsys-tarfile",   0,   0,  0, 0,               setaction        },
+  { "control-tarfile",0,   0,  0, 0,               setaction        },
+  { "new",            0,   0,  &oldformatflag, 0,  0,            0  },
+  { "old",            0,   0,  &oldformatflag, 0,  0,            1  },
+  { "debug",         'D',  0,  &debugflag,     0,  0,            1  },
+  { "nocheck",        0,   0,  &nocheckflag,   0,  0,            1  },
+  { "compression",   'z',  1,  0,   &compression,  0,            1  },
+  { "help",          'h',  0,  0, 0,               helponly         },
+  { "version",        0,   0,  0, 0,               versiononly      },
+  { "licence",        0,   0,  0, 0,               showcopyright    }, /* UK spelling */
+  { "license",        0,   0,  0, 0,               showcopyright    }, /* US spelling */
+  {  0,               0                                             }
 };
 
 static void setaction(const struct cmdinfo *cip, const char *value) {
