Last active
October 9, 2015 23:48
-
-
Save lotz84/4eb6712d6b8656a60ef8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.Binary (Binary) | |
import qualified Data.Binary as Bin | |
import qualified Codec.Compression.GZip as GZip | |
import qualified Data.ByteString.Lazy.Char8 as BL | |
pickle :: Binary a => FilePath -> a -> IO () | |
pickle path = BL.writeFile path . GZip.compress . Bin.encode | |
unpickle :: Binary a => FilePath -> IO a | |
unpickle path = Bin.decode . GZip.decompress <$> BL.readFile path | |
main :: IO () | |
main = do | |
let largeData = map (\i -> (i, show i)) [1..10000] :: [(Int, String)] | |
pickle "save.dat" largeData | |
-- 36KB | |
BL.writeFile "save.txt" . GZip.compress . BL.pack . show $ largeData | |
-- 46KB |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment