Skip to content

Instantly share code, notes, and snippets.

@AlexeyRaga
Created February 14, 2016 10:34
Show Gist options
  • Select an option

  • Save AlexeyRaga/caa7c9e76ccc2dd5a863 to your computer and use it in GitHub Desktop.

Select an option

Save AlexeyRaga/caa7c9e76ccc2dd5a863 to your computer and use it in GitHub Desktop.
Haskell decompress with error handling using Pipes
name: andy
version: 0.1.0.0
synopsis: Simple project template from stack
description: Please see README.md
license: BSD3
license-file: LICENSE
author: Alexey Raga
maintainer: [email protected]
copyright: Alexey Raga
category: Services
build-type: Simple
cabal-version: >=1.10
executable andy
hs-source-dirs: src
main-is: Main.hs
default-language: Haskell2010
build-depends: base >= 4.7 && < 5
, bytestring
, directory
, filemanip
, filepath
, mtl
, pipes
, pipes-bytestring
, pipes-safe
, pipes-zlib
, regex-posix
, unix
, unix-compat
, xml
, zlib
module Main where
import Data.ByteString (ByteString)
import Pipes
import Pipes.ByteString
import Pipes.GZip
import Pipes.Safe
import Pipes.Safe.Prelude (withFile)
import System.IO (IOMode(..))
bad = "/Users/alexey/Work/run.sh"
good = "/Users/alexey/Work/split.py.gz"
main =
tryRun . runSafeT . runEffect $
(decompress $ readBinaryFile good) >-> stdout
tryRun :: IO a -> IO (Either SomeException a)
tryRun = try
readBinaryFile :: MonadSafe m => FilePath -> Producer ByteString m ()
readBinaryFile file = withFile file ReadMode fromHandle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment