From 643d2d72fab23df30d29c10614bfa89648cd3655 Mon Sep 17 00:00:00 2001
From: pacien
Date: Sat, 24 Nov 2018 01:03:43 +0100
Subject: Implement program entry point
---
src/main.nim | 40 +++++++++++++++++++++++++++++++++++++++-
1 file changed, 39 insertions(+), 1 deletion(-)
(limited to 'src')
diff --git a/src/main.nim b/src/main.nim
index dbf331f..8f0536c 100644
--- a/src/main.nim
+++ b/src/main.nim
@@ -14,5 +14,43 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see .
+import os, streams, sugar
+import bitreader, bitwriter, streamblock
+
+proc transform(operation: (BitReader, BitWriter) -> void, input, output: string) =
+ let inputStream = openFileStream(input, fmRead)
+ defer: inputStream.close()
+ let outputStream = openFileStream(output, fmWrite)
+ defer: outputStream.close()
+ operation(inputStream.bitReader(), outputStream.bitWriter())
+
+proc compress(bitReader: BitReader, bitWriter: BitWriter) =
+ while not bitReader.atEnd():
+ let streamBlock = streamblock.readRaw(bitReader)
+ streamBlock.writeSerialisedTo(bitWriter)
+ bitWriter.flush()
+
+proc decompress(bitReader: BitReader, bitWriter: BitWriter) =
+ var hasMore = true
+ while hasMore:
+ let streamBlock = streamblock.readSerialised(bitReader)
+ streamBlock.writeRawTo(bitWriter)
+ hasMore = not streamBlock.isLast()
+ bitWriter.flush()
+
+proc printUsage(output: File) =
+ output.writeLine("Usage: " & paramStr(0) & "