diff --git a/LICENSE b/LICENSE
new file mode 100644
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,22 @@
+Copyright (c) 2018, Metrix.AI
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
diff --git a/Setup.hs b/Setup.hs
new file mode 100644
--- /dev/null
+++ b/Setup.hs
@@ -0,0 +1,2 @@
+import Distribution.Simple
+main = defaultMain
diff --git a/library/Potoki/Zlib/Fetch.hs b/library/Potoki/Zlib/Fetch.hs
new file mode 100644
--- /dev/null
+++ b/library/Potoki/Zlib/Fetch.hs
@@ -0,0 +1,60 @@
+module Potoki.Zlib.Fetch (
+  runGzip,
+  withCounter,
+) where
+
+import Potoki.Zlib.Prelude
+import Potoki.Core.Fetch
+import Potoki.Core.Consume
+import qualified Codec.Compression.Zlib.Internal as A
+
+
+withConsumeHook :: Consume a b -> (a -> IO ()) -> Consume a b
+withConsumeHook (Consume consume) hook =
+  Consume $ \ (Fetch fetchIO) -> consume $ Fetch $ do
+    fetch <- fetchIO
+    case fetch of
+      Nothing -> return Nothing
+      Just val -> Just val <$ hook val
+
+withCounter :: Consume a b -> (Int -> IO ()) -> Consume a b
+withCounter consume int2IO =
+  do
+    counterVar <- liftIO $ newIORef 0
+    withConsumeHook consume $ \_ -> do
+      modifyIORef' counterVar succ
+      readIORef counterVar >>= int2IO
+
+runGzip :: IORef [ByteString]
+        -> IORef (A.DecompressStream IO)
+        -> Fetch ByteString
+        -> Fetch (Either A.DecompressError ByteString)
+runGzip unfetchedChunksRef resultRef (Fetch oldFetchIO) =
+  Fetch $ do
+    let
+      interpretResult resultIO = do
+        result <- resultIO
+        case result of
+          A.DecompressInputRequired nextResult -> do
+            newResult <- do
+              oldFetch <- oldFetchIO
+              return $ case oldFetch of
+                Nothing  -> nextResult mempty
+                Just val -> nextResult val
+            interpretResult newResult
+          A.DecompressOutputAvailable decompressOutput decompressNext -> do
+            --                     :: !S.ByteString -> m (DecompressStream m)
+            nextResult <- decompressNext
+            writeIORef resultRef nextResult
+            -- writeIORef unfetchedChunksRef nextResult -- TODO: not needed??
+            return (Just (Right decompressOutput))
+          A.DecompressStreamEnd _ ->
+            return Nothing
+          A.DecompressStreamError err ->
+            return (Just (Left err))
+    unfetchedChunks <- readIORef unfetchedChunksRef
+    case unfetchedChunks of
+      headChunk : unfetchedChunksTail -> do
+        writeIORef unfetchedChunksRef unfetchedChunksTail
+        return (Just (Right headChunk))
+      _ -> interpretResult $ readIORef resultRef
diff --git a/library/Potoki/Zlib/Prelude.hs b/library/Potoki/Zlib/Prelude.hs
new file mode 100644
--- /dev/null
+++ b/library/Potoki/Zlib/Prelude.hs
@@ -0,0 +1,14 @@
+module Potoki.Zlib.Prelude
+(
+  module Exports,
+)
+where
+
+
+import Data.ByteString as Exports (ByteString)
+import Data.Either as Exports
+import Data.IORef as Exports
+import Prelude as Exports
+import Control.Monad as Exports
+import Control.Monad.IO.Class as Exports
+
diff --git a/library/Potoki/Zlib/Transform.hs b/library/Potoki/Zlib/Transform.hs
new file mode 100644
--- /dev/null
+++ b/library/Potoki/Zlib/Transform.hs
@@ -0,0 +1,25 @@
+module Potoki.Zlib.Transform
+(
+  decompress
+)
+where
+
+import Potoki.Zlib.Prelude
+import qualified Potoki.Zlib.Fetch as Z
+import Potoki.Core.Transform (Transform(..))
+import qualified Codec.Compression.Zlib.Internal as I
+import qualified Acquire.Acquire as A
+
+
+decompress :: Transform ByteString (Either I.DecompressError ByteString)
+decompress =
+  Transform $ \oldFetchIO -> A.Acquire $ do
+    initChunksRef <- newIORef []
+    decompRef <- newIORef (I.decompressIO I.gzipFormat I.defaultDecompressParams)
+    let
+      fetch =
+        Z.runGzip initChunksRef decompRef oldFetchIO
+      kill =
+        return ()
+    return (fetch, kill)
+
diff --git a/potoki-zlib.cabal b/potoki-zlib.cabal
new file mode 100644
--- /dev/null
+++ b/potoki-zlib.cabal
@@ -0,0 +1,61 @@
+name:
+  potoki-zlib
+version:
+  0.3
+synopsis:
+  Streaming ZLib decompression
+category:
+  Potoki, Streaming, ZLib, Compression
+homepage:
+  https://github.com/nikita-volkov/potoki-zlib
+bug-reports:
+  https://github.com/nikita-volkov/potoki-zlib/issues
+author:
+  Ilya Zubkov <izubkov.forall@gmail.com>
+maintainer:
+  Ilya Zubkov <izubkov.forall@gmail.com>
+copyright:
+  (c) 2018, Metrix.AI
+license:
+  MIT
+license-file:
+  LICENSE
+build-type:
+  Simple
+cabal-version:
+  >=1.10
+
+source-repository head
+  type:
+    git
+  location:
+    git://github.com/nikita-volkov/potoki-zlib.git
+
+library
+  hs-source-dirs:
+    library
+  default-extensions:
+    Arrows, BangPatterns, ConstraintKinds, DataKinds,
+    DefaultSignatures, DeriveDataTypeable, DeriveFoldable,
+    DeriveFunctor, DeriveGeneric, DeriveTraversable, EmptyDataDecls,
+    FlexibleContexts, FlexibleInstances, FunctionalDependencies, GADTs,
+    GeneralizedNewtypeDeriving, LambdaCase, LiberalTypeSynonyms,
+    MagicHash, MultiParamTypeClasses, MultiWayIf, NoImplicitPrelude,
+    NoMonomorphismRestriction, OverloadedStrings, PatternGuards,
+    ParallelListComp, QuasiQuotes, RankNTypes, RecordWildCards,
+    ScopedTypeVariables, StandaloneDeriving, TemplateHaskell,
+    TupleSections, TypeFamilies, TypeOperators, UnboxedTuples
+  default-language:
+    Haskell2010
+  exposed-modules:
+    Potoki.Zlib.Transform
+    Potoki.Zlib.Fetch
+  other-modules:
+    Potoki.Zlib.Prelude
+  build-depends:
+    acquire >= 0.2 && < 0.3,
+    base >=4.7 && <5,
+    bytestring >=0.10 && <0.11,
+    potoki-core >= 2.1 && < 2.2,
+    zlib >= 0.6.1.2 && < 0.7
+
