@@ -45,6 +45,7 @@ module Codec.Compression.Zlib.Internal (
45
45
defaultCompressParams ,
46
46
DecompressParams (.. ),
47
47
defaultDecompressParams ,
48
+ Stream. Flush (.. ),
48
49
Stream. Format (.. ),
49
50
Stream. gzipFormat ,
50
51
Stream. zlibFormat ,
@@ -111,7 +112,8 @@ data CompressParams = CompressParams {
111
112
compressMemoryLevel :: ! Stream. MemoryLevel ,
112
113
compressStrategy :: ! Stream. CompressionStrategy ,
113
114
compressBufferSize :: ! Int ,
114
- compressDictionary :: Maybe S. ByteString
115
+ compressDictionary :: Maybe S. ByteString ,
116
+ compressFlush :: ! Stream. Flush
115
117
} deriving Show
116
118
117
119
-- | The full set of parameters for decompression. The defaults are
@@ -137,7 +139,8 @@ data DecompressParams = DecompressParams {
137
139
decompressWindowBits :: ! Stream. WindowBits ,
138
140
decompressBufferSize :: ! Int ,
139
141
decompressDictionary :: Maybe S. ByteString ,
140
- decompressAllMembers :: Bool
142
+ decompressAllMembers :: Bool ,
143
+ decompressFlush :: ! Stream. Flush
141
144
} deriving Show
142
145
143
146
-- | The default set of parameters for compression. This is typically used with
@@ -151,7 +154,8 @@ defaultCompressParams = CompressParams {
151
154
compressMemoryLevel = Stream. defaultMemoryLevel,
152
155
compressStrategy = Stream. defaultStrategy,
153
156
compressBufferSize = defaultCompressBufferSize,
154
- compressDictionary = Nothing
157
+ compressDictionary = Nothing ,
158
+ compressFlush = Stream. NoFlush
155
159
}
156
160
157
161
-- | The default set of parameters for decompression. This is typically used with
@@ -162,7 +166,8 @@ defaultDecompressParams = DecompressParams {
162
166
decompressWindowBits = Stream. defaultWindowBits,
163
167
decompressBufferSize = defaultDecompressBufferSize,
164
168
decompressDictionary = Nothing ,
165
- decompressAllMembers = True
169
+ decompressAllMembers = True ,
170
+ decompressFlush = Stream. NoFlush
166
171
}
167
172
168
173
-- | The default chunk sizes for the output of compression and decompression
@@ -466,7 +471,7 @@ compressIO format params = compressStreamIO format params
466
471
compressStream :: Stream. Format -> CompressParams -> S. ByteString
467
472
-> Stream (CompressStream Stream )
468
473
compressStream format (CompressParams compLevel method bits memLevel
469
- strategy initChunkSize mdict) =
474
+ strategy initChunkSize mdict flushStrategy ) =
470
475
471
476
\ chunk -> do
472
477
Stream. deflateInit format compLevel method bits memLevel strategy
@@ -526,13 +531,13 @@ compressStream format (CompressParams compLevel method bits memLevel
526
531
-- this invariant guarantees we can always make forward progress
527
532
-- and that therefore a BufferError is impossible
528
533
529
- let flush = if lastChunk then Stream. Finish else Stream. NoFlush
534
+ let flush = if lastChunk then Stream. Finish else flushStrategy
530
535
status <- Stream. deflate flush
531
536
532
537
case status of
533
538
Stream. Ok -> do
534
539
outputBufferFull <- Stream. outputBufferFull
535
- if outputBufferFull
540
+ if outputBufferFull || flushStrategy /= Stream. NoFlush
536
541
then do (outFPtr, offset, length ) <- Stream. popOutputBuffer
537
542
let chunk = S. PS outFPtr offset length
538
543
return $ CompressOutputAvailable chunk $ do
@@ -596,7 +601,7 @@ decompressIO format params = decompressStreamIO format params
596
601
decompressStream :: Stream. Format -> DecompressParams
597
602
-> Bool -> S. ByteString
598
603
-> Stream (DecompressStream Stream )
599
- decompressStream format (DecompressParams bits initChunkSize mdict allMembers)
604
+ decompressStream format (DecompressParams bits initChunkSize mdict allMembers flushStrategy )
600
605
resume =
601
606
602
607
\ chunk -> do
@@ -675,12 +680,12 @@ decompressStream format (DecompressParams bits initChunkSize mdict allMembers)
675
680
-- this invariant guarantees we can always make forward progress or at
676
681
-- least if a BufferError does occur that it must be due to a premature EOF
677
682
678
- status <- Stream. inflate Stream. NoFlush
683
+ status <- Stream. inflate flushStrategy
679
684
680
685
case status of
681
686
Stream. Ok -> do
682
687
outputBufferFull <- Stream. outputBufferFull
683
- if outputBufferFull
688
+ if outputBufferFull || flushStrategy /= Stream. NoFlush
684
689
then do (outFPtr, offset, length ) <- Stream. popOutputBuffer
685
690
let chunk = S. PS outFPtr offset length
686
691
return $ DecompressOutputAvailable chunk $ do
0 commit comments