root / src / Ganeti / Codec.hs @ a1f35d0a
History | View | Annotate | Download (1.6 kB)
1 | 8c337f87 | Petr Pudlak | {-| Provides interface to the 'zlib' library. |
---|---|---|---|
2 | 8c337f87 | Petr Pudlak | |
3 | 8c337f87 | Petr Pudlak | -} |
4 | 8c337f87 | Petr Pudlak | |
5 | 8c337f87 | Petr Pudlak | {- |
6 | 8c337f87 | Petr Pudlak | |
7 | 8c337f87 | Petr Pudlak | Copyright (C) 2014 Google Inc. |
8 | 8c337f87 | Petr Pudlak | |
9 | 8c337f87 | Petr Pudlak | This program is free software; you can redistribute it and/or modify |
10 | 8c337f87 | Petr Pudlak | it under the terms of the GNU General Public License as published by |
11 | 8c337f87 | Petr Pudlak | the Free Software Foundation; either version 2 of the License, or |
12 | 8c337f87 | Petr Pudlak | (at your option) any later version. |
13 | 8c337f87 | Petr Pudlak | |
14 | 8c337f87 | Petr Pudlak | This program is distributed in the hope that it will be useful, but |
15 | 8c337f87 | Petr Pudlak | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | 8c337f87 | Petr Pudlak | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
17 | 8c337f87 | Petr Pudlak | General Public License for more details. |
18 | 8c337f87 | Petr Pudlak | |
19 | 8c337f87 | Petr Pudlak | You should have received a copy of the GNU General Public License |
20 | 8c337f87 | Petr Pudlak | along with this program; if not, write to the Free Software |
21 | 8c337f87 | Petr Pudlak | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
22 | 8c337f87 | Petr Pudlak | 02110-1301, USA. |
23 | 8c337f87 | Petr Pudlak | |
24 | 8c337f87 | Petr Pudlak | -} |
25 | 8c337f87 | Petr Pudlak | |
26 | 8c337f87 | Petr Pudlak | module Ganeti.Codec |
27 | 8c337f87 | Petr Pudlak | ( compressZlib |
28 | 8c337f87 | Petr Pudlak | , decompressZlib |
29 | 8c337f87 | Petr Pudlak | ) where |
30 | 8c337f87 | Petr Pudlak | |
31 | 8c337f87 | Petr Pudlak | import Codec.Compression.Zlib (compress) |
32 | 8c337f87 | Petr Pudlak | import qualified Codec.Compression.Zlib.Internal as I |
33 | 8c337f87 | Petr Pudlak | import Control.Monad.Error |
34 | 8c337f87 | Petr Pudlak | import qualified Data.ByteString.Lazy as BL |
35 | 8c337f87 | Petr Pudlak | import qualified Data.ByteString.Lazy.Internal as BL |
36 | 8c337f87 | Petr Pudlak | import Data.Monoid (mempty) |
37 | 8c337f87 | Petr Pudlak | |
38 | 8c337f87 | Petr Pudlak | -- | Compresses a lazy bytestring. |
39 | 8c337f87 | Petr Pudlak | compressZlib :: BL.ByteString -> BL.ByteString |
40 | 8c337f87 | Petr Pudlak | compressZlib = compress |
41 | 8c337f87 | Petr Pudlak | |
42 | 8c337f87 | Petr Pudlak | -- | Decompresses a lazy bytestring, throwing decoding errors using |
43 | 8c337f87 | Petr Pudlak | -- 'throwError'. |
44 | 8c337f87 | Petr Pudlak | decompressZlib :: (MonadError e m, Error e) => BL.ByteString -> m BL.ByteString |
45 | 8c337f87 | Petr Pudlak | decompressZlib = I.foldDecompressStream |
46 | 8c337f87 | Petr Pudlak | (liftM . BL.chunk) |
47 | 8c337f87 | Petr Pudlak | (return mempty) |
48 | 8c337f87 | Petr Pudlak | (const $ throwError . strMsg . ("Zlib: " ++)) |
49 | 8c337f87 | Petr Pudlak | . I.decompressWithErrors |
50 | 8c337f87 | Petr Pudlak | I.zlibFormat |
51 | 8c337f87 | Petr Pudlak | I.defaultDecompressParams |