haskell-compression (empty) → 0.1
raw patch · 7 files changed
+125/−0 lines, 7 filesdep +basedep +bimapdep +boolean-listsetup-changed
Dependencies added: base, bimap, boolean-list, bytestring, containers
Files
- Codec/HaskellCompression.hs +10/−0
- Codec/HaskellCompression/Shared.hs +25/−0
- Codec/HaskellCompression/Unzip.hs +28/−0
- Codec/HaskellCompression/Zip.hs +21/−0
- Main.hs +16/−0
- Setup.lhs +3/−0
- haskell-compression.cabal +22/−0
+ Codec/HaskellCompression.hs view
@@ -0,0 +1,10 @@+module Codec.HaskellCompression (+ zipit+,unzipt+) where ++import qualified Codec.HaskellCompression.Zip+import qualified Codec.HaskellCompression.Unzip++zipit = Codec.HaskellCompression.Zip.zipit+unzipit = Codec.HaskellCompression.Unzip.unzipit
@@ -0,0 +1,25 @@+module Codec.HaskellCompression.Shared where++import Data.List+import qualified Data.Bimap as Map+import Data.Maybe+import Data.BooleanList+import qualified Data.ByteString as B (pack,unpack,ByteString)+import Control.Arrow++viaNum f d = B.pack ( map fromIntegral (f ( map fromIntegral (B.unpack d))))++startingLength = fromIntegral 9 +viaBool f ns = int8Chunks (f (toBoolean8s ns))++lengthOfKeys = (2 ^ (startingLength - 1)) - 1++initdb :: Map.Bimap [[Bool]] Int+initdb = Map.fromList (Data.List.zipWith (\x y ->([x],y)) (integersToBooleanListsPadded startingLength [0..lengthOfKeys]) [0..])++++initdb2 :: Map.Bimap (Maybe Int,Int) Int+initdb2 = Map.fromList (Data.List.zipWith (\x y ->((Nothing,fromIntegral x),fromIntegral y)) [0..lengthOfKeys] [0..])++via = viaNum . viaBool
+ Codec/HaskellCompression/Unzip.hs view
@@ -0,0 +1,28 @@+module Codec.HaskellCompression.Unzip where +import Data.List+import qualified Data.Bimap as Map+import Data.Maybe+import Data.BooleanList+import qualified Data.ByteString as B (pack,unpack,ByteString)+import Control.Arrow+import Codec.HaskellCompression.Shared+import Debug.Trace+import Data.Char++takeLast n xs = drop (length xs-n) xs++unzipit = via (\xs -> let (headxs,tailxs) = splitAt (fromIntegral startingLength) xs in if xs == [] then [] else unzipit' initdb headxs tailxs)++unzipit' :: Map.Bimap [[Bool]] Int -> [Bool] -> [Bool] -> [Bool]+unzipit' library buffer xs = let+ librarySize = Map.size library+ keyLength = boolsRequiredForInteger $ (+1) $ librarySize + (headxs,tailxs) = splitAt (fromIntegral keyLength) xs+ Just key = booleanListToInteger buffer `Map.lookupR` library+ ref = fromJust $ if (booleanListToInteger headxs) == librarySize then Just key else (booleanListToInteger headxs) `Map.lookupR` library+ in if length headxs < (fromIntegral keyLength) then concat $ map (padBooleanList 8. takeLast 8) $ library Map.!> booleanListToInteger buffer+ else case Map.lookup [pruneBooleanList buffer,pruneBooleanList headxs] library of+ Just n -> unzipit' library (integerToBooleanList n) tailxs+ Nothing -> (concat $ map ( padBooleanList 8 . takeLast 8) key) ++ (unzipit' ((Map.insert ( map pruneBooleanList $ concat $ [key ,take 1 ref])) (librarySize) library) headxs tailxs)++
+ Codec/HaskellCompression/Zip.hs view
@@ -0,0 +1,21 @@+module Codec.HaskellCompression.Zip where +import Data.List+import qualified Data.Bimap as Map+import Data.Maybe+import Data.BooleanList+import qualified Data.ByteString as B (pack,unpack,ByteString)+import Control.Arrow+import Codec.HaskellCompression.Shared++zipit :: B.ByteString -> B.ByteString+zipit = via (\xs -> let (headxs,tailxs) = splitAt 8 xs in if xs == [] then [] else zipit' initdb2 (booleanListToInteger headxs) tailxs)++zipit' :: Map.Bimap (Maybe Int,Int) Int -> Int -> [Bool] -> [Bool]+zipit' library buffer xs = let+ librarySize = Map.size library+ keyLength = boolsRequiredForInteger librarySize + (headxs,tailxs) = splitAt 8 xs+ key = (Just buffer, booleanListToInteger headxs)+ in if xs == [] then (integerToBooleanListPadded (fromIntegral keyLength) buffer) else case Map.lookup key library of+ Just n -> zipit' library n tailxs+ _ -> ( integerToBooleanListPadded (fromIntegral keyLength) buffer) ++ zipit' (Map.insert key librarySize library) (booleanListToInteger headxs) tailxs
+ Main.hs view
@@ -0,0 +1,16 @@+module Main where++import Codec.HaskellCompression+import System.Environment+import qualified Data.ByteString (interact) ++main = do+ args <- getArgs+ case args of+ [arg] -> case arg of+ "zip" -> Data.ByteString.interact zipit+ "unzip" -> Data.ByteString.interact unzipit+ _ -> usage+ _ -> usage++usage = putStrLn "Usage: zip|unzip"
+ Setup.lhs view
@@ -0,0 +1,3 @@+#!/usr/bin/env runhaskell+> import Distribution.Simple+> main = defaultMain
+ haskell-compression.cabal view
@@ -0,0 +1,22 @@+name: haskell-compression+version: 0.1+synopsis: +description: Compress files+category: Codec+license: BSD3+author: Alan Hawkins+homepage: codekinder.com+maintainer: hawk.alan@gmail.com+cabal-version: >= 1.2+build-type: Simple++executable hs-compress+ main-is: Main.hs+ build-depends: base<10000 , containers, bytestring,bimap, boolean-list+ +library+ exposed-modules: Codec.HaskellCompression+ other-modules: Codec.HaskellCompression.Zip+ ,Codec.HaskellCompression.Unzip+ ,Codec.HaskellCompression.Shared+ build-depends: base <10000, containers, bytestring,bimap,boolean-list