]> mj.ucw.cz Git - libucw.git/blobdiff - lib/buckettool.c
tested the wrapper guarding the safe decompression
[libucw.git] / lib / buckettool.c
index aeec5373def62cc4861c6558fd2436068e19be54..179e3d98ea67e10844be6dfe4b33a8f94ed7d844 100644 (file)
@@ -118,14 +118,19 @@ insert(byte *arg)
   obuck_init(1);
   do
     {
-      b = obuck_create(type);
+      b = NULL;
       while ((e = bgets(in, buf, sizeof(buf))) && buf[0])
        {
          *e++ = '\n';
+         if (!b)
+           b = obuck_create(type);
          bwrite(b, buf, e-buf);
        }
-      obuck_create_end(b, &h);
-      printf("%08x %d %08x\n", h.oid, h.length, h.type);
+      if (b)
+       {
+         obuck_create_end(b, &h);
+         printf("%08x %d %08x\n", h.oid, h.length, h.type);
+       }
     }
   while (e);
   obuck_cleanup();
@@ -136,23 +141,25 @@ static void
 cat(void)
 {
   struct obuck_header h;
-  struct fastbuf *b;
+  struct fastbuf *b, *out;
   byte buf[1024];
   int l, lf;
 
   obuck_init(0);
+  out = bfdopen_shared(1, 65536);
   while (b = obuck_slurp_pool(&h))
     {
-      printf("### %08x %6d %08x\n", h.oid, h.length, h.type);
+      bprintf(out, "### %08x %6d %08x\n", h.oid, h.length, h.type);
       lf = 1;
       while ((l = bread(b, buf, sizeof(buf))))
        {
-         fwrite(buf, 1, l, stdout);
+         bwrite(out, buf, l);
          lf = (buf[l-1] == '\n');
        }
       if (!lf)
-       printf("\n# <missing EOL>\n");
+       bprintf(out, "\n# <missing EOL>\n");
     }
+  bclose(out);
   obuck_cleanup();
 }