aboutsummaryrefslogtreecommitdiff
path: root/tests/lz4/driver.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2021-03-09 12:58:34 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2021-03-12 13:00:12 +0200
commitf4cd7abdd38aa3d14dcce98cb92dc1054fe97503 (patch)
tree4839d7b862ca6ded5191991f610dd6cf17ac1fde /tests/lz4/driver.cxx
parentff9995f1e638ada66a68a54475adea7c9191916b (diff)
Add support for compressing/decompressing fdstreams with LZ4
Importing LZ4 code from version 1.9.3.
Diffstat (limited to 'tests/lz4/driver.cxx')
-rw-r--r--tests/lz4/driver.cxx47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/lz4/driver.cxx b/tests/lz4/driver.cxx
new file mode 100644
index 0000000..e3da5e6
--- /dev/null
+++ b/tests/lz4/driver.cxx
@@ -0,0 +1,47 @@
+// file : tests/lz4/driver.cxx -*- C++ -*-
+// license : MIT; see accompanying LICENSE file
+
+#include <iostream>
+#include <exception>
+
+#include <libbutl/lz4.hxx>
+#include <libbutl/fdstream.mxx>
+#include <libbutl/filesystem.mxx> // entry_stat, path_entry()
+
+using namespace std;
+using namespace butl;
+
+// Usage: argv[0] [-c|-d] <input-file> <output-file>
+//
+int
+main (int argc, const char* argv[])
+try
+{
+ assert (argc == 4);
+
+ ifdstream ifs (argv[2], fdopen_mode::binary, ifdstream::badbit);
+ ofdstream ofs (argv[3], fdopen_mode::binary);
+
+ if (argv[1][1] == 'c')
+ {
+ // @@ TODO: would be nice to get it from fd.
+ //
+ entry_stat st (path_entry (argv[2], true /* follow_symlinks */).second);
+
+ lz4::compress (ofs, ifs,
+ 1 /* compression_level */,
+ 4 /* block_size_id (64KB) */,
+ st.size);
+ }
+ else
+ {
+ lz4::decompress (ofs, ifs);
+ }
+
+ ofs.close ();
+}
+catch (const std::exception& e)
+{
+ cerr << e.what () << endl;
+ return 1;
+}