about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2016-04-29T15·47+0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2016-04-29T15·47+0200
commit83258225e6be25cd706df0f96dcbd4b04c352056 (patch)
treefa1392141f126732e1dba0d90301733b6260afdf /src
parent4dde0b0562115525f76943653357410835910a99 (diff)
nix-store -l: Simplify implementation
Diffstat (limited to 'src')
-rw-r--r--src/nix-store/nix-store.cc17
1 files changed, 2 insertions, 15 deletions
diff --git a/src/nix-store/nix-store.cc b/src/nix-store/nix-store.cc
index 3a7fcdf4e0e4..653a95f21679 100644
--- a/src/nix-store/nix-store.cc
+++ b/src/nix-store/nix-store.cc
@@ -9,6 +9,7 @@
 #include "util.hh"
 #include "worker-protocol.hh"
 #include "xmlgraph.hh"
+#include "compression.hh"
 
 #include <iostream>
 #include <algorithm>
@@ -502,21 +503,7 @@ static void opReadLog(Strings opFlags, Strings opArgs)
             }
 
             else if (pathExists(logBz2Path)) {
-                AutoCloseFD fd = open(logBz2Path.c_str(), O_RDONLY);
-                FILE * f = 0;
-                if (fd == -1 || (f = fdopen(fd.borrow(), "r")) == 0)
-                    throw SysError(format("opening file ‘%1%’") % logBz2Path);
-                int err;
-                BZFILE * bz = BZ2_bzReadOpen(&err, f, 0, 0, 0, 0);
-                if (!bz) throw Error(format("cannot open bzip2 file ‘%1%’") % logBz2Path);
-                unsigned char buf[128 * 1024];
-                do {
-                    int n = BZ2_bzRead(&err, bz, buf, sizeof(buf));
-                    if (err != BZ_OK && err != BZ_STREAM_END)
-                        throw Error(format("error reading bzip2 file ‘%1%’") % logBz2Path);
-                    writeFull(STDOUT_FILENO, buf, n);
-                } while (err != BZ_STREAM_END);
-                BZ2_bzReadClose(&err, bz);
+                std::cout << *decompress("bzip2", make_ref<std::string>(readFile(logBz2Path)));
                 found = true;
                 break;
             }