Last active
February 14, 2016 03:36
-
-
Save AlexeyRaga/3e4be1fceb5860b4277b to your computer and use it in GitHub Desktop.
Streaming ungzip with error handling
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
| 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: alexey.raga@somewhere.else | |
| 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 | |
| , regex-posix | |
| , unix | |
| , unix-compat | |
| , xml | |
| , zlib | |
| , conduit | |
| , bzlib-conduit | |
| , binary-conduit | |
| , conduit-extra | |
| , resourcet |
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
| {-# LANGUAGE OverloadedStrings #-} | |
| module Main where | |
| import Control.Exception | |
| import Control.Monad.Trans.Resource (runResourceT) | |
| import Data.ByteString (ByteString) | |
| import Data.Conduit (($$), ($=), catchC, yield) | |
| import Data.Conduit.Binary | |
| import Data.Conduit.Zlib | |
| import System.IO | |
| bad = "/Users/alexey/Work/run.sh" | |
| good = "/Users/alexey/Work/split.py.gz" | |
| main = unzipFile bad | |
| unzipFile :: String -> IO () | |
| unzipFile name = runResourceT $ | |
| sourceFile name | |
| $= (ungzip `catchC` (yield . compensate)) | |
| $$ sinkHandle stdout | |
| compensate :: SomeException -> ByteString | |
| compensate _ = "No data for you bro" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment