Skip to content

Instantly share code, notes, and snippets.

@lotz84
Last active October 9, 2015 23:48
Show Gist options
  • Save lotz84/4eb6712d6b8656a60ef8 to your computer and use it in GitHub Desktop.
Save lotz84/4eb6712d6b8656a60ef8 to your computer and use it in GitHub Desktop.
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