@@ -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 ,
@@ -105,7 +106,8 @@ data CompressParams = CompressParams {
105
106
compressMemoryLevel :: ! Stream. MemoryLevel ,
106
107
compressStrategy :: ! Stream. CompressionStrategy ,
107
108
compressBufferSize :: ! Int ,
108
- compressDictionary :: Maybe S. ByteString
109
+ compressDictionary :: Maybe S. ByteString ,
110
+ compressFlush :: ! Stream. Flush
109
111
} deriving Show
110
112
111
113
-- | The full set of parameters for decompression. The defaults are
@@ -131,7 +133,8 @@ data DecompressParams = DecompressParams {
131
133
decompressWindowBits :: ! Stream. WindowBits ,
132
134
decompressBufferSize :: ! Int ,
133
135
decompressDictionary :: Maybe S. ByteString ,
134
- decompressAllMembers :: Bool
136
+ decompressAllMembers :: Bool ,
137
+ decompressFlush :: ! Stream. Flush
135
138
} deriving Show
136
139
137
140
-- | The default set of parameters for compression. This is typically used with
@@ -145,7 +148,8 @@ defaultCompressParams = CompressParams {
145
148
compressMemoryLevel = Stream. defaultMemoryLevel,
146
149
compressStrategy = Stream. defaultStrategy,
147
150
compressBufferSize = defaultCompressBufferSize,
148
- compressDictionary = Nothing
151
+ compressDictionary = Nothing ,
152
+ compressFlush = Stream. NoFlush
149
153
}
150
154
151
155
-- | The default set of parameters for decompression. This is typically used with
@@ -156,7 +160,8 @@ defaultDecompressParams = DecompressParams {
156
160
decompressWindowBits = Stream. defaultWindowBits,
157
161
decompressBufferSize = defaultDecompressBufferSize,
158
162
decompressDictionary = Nothing ,
159
- decompressAllMembers = True
163
+ decompressAllMembers = True ,
164
+ decompressFlush = Stream. NoFlush
160
165
}
161
166
162
167
-- | The default chunk sizes for the output of compression and decompression
@@ -460,7 +465,7 @@ compressIO format params = compressStreamIO format params
460
465
compressStream :: Stream. Format -> CompressParams -> S. ByteString
461
466
-> Stream (CompressStream Stream )
462
467
compressStream format (CompressParams compLevel method bits memLevel
463
- strategy initChunkSize mdict) =
468
+ strategy initChunkSize mdict flushStrategy ) =
464
469
465
470
\ chunk -> do
466
471
Stream. deflateInit format compLevel method bits memLevel strategy
@@ -520,13 +525,13 @@ compressStream format (CompressParams compLevel method bits memLevel
520
525
-- this invariant guarantees we can always make forward progress
521
526
-- and that therefore a BufferError is impossible
522
527
523
- let flush = if lastChunk then Stream. Finish else Stream. NoFlush
528
+ let flush = if lastChunk then Stream. Finish else flushStrategy
524
529
status <- Stream. deflate flush
525
530
526
531
case status of
527
532
Stream. Ok -> do
528
533
outputBufferFull <- Stream. outputBufferFull
529
- if outputBufferFull
534
+ if outputBufferFull || flushStrategy /= Stream. NoFlush
530
535
then do (outFPtr, offset, length ) <- Stream. popOutputBuffer
531
536
let chunk = S. PS outFPtr offset length
532
537
return $ CompressOutputAvailable chunk $ do
@@ -590,7 +595,7 @@ decompressIO format params = decompressStreamIO format params
590
595
decompressStream :: Stream. Format -> DecompressParams
591
596
-> Bool -> S. ByteString
592
597
-> Stream (DecompressStream Stream )
593
- decompressStream format (DecompressParams bits initChunkSize mdict allMembers)
598
+ decompressStream format (DecompressParams bits initChunkSize mdict allMembers flushStrategy )
594
599
resume =
595
600
596
601
\ chunk -> do
@@ -669,12 +674,12 @@ decompressStream format (DecompressParams bits initChunkSize mdict allMembers)
669
674
-- this invariant guarantees we can always make forward progress or at
670
675
-- least if a BufferError does occur that it must be due to a premature EOF
671
676
672
- status <- Stream. inflate Stream. NoFlush
677
+ status <- Stream. inflate flushStrategy
673
678
674
679
case status of
675
680
Stream. Ok -> do
676
681
outputBufferFull <- Stream. outputBufferFull
677
- if outputBufferFull
682
+ if outputBufferFull || flushStrategy /= Stream. NoFlush
678
683
then do (outFPtr, offset, length ) <- Stream. popOutputBuffer
679
684
let chunk = S. PS outFPtr offset length
680
685
return $ DecompressOutputAvailable chunk $ do
0 commit comments