Skip to content

Commit 67bc94d

Browse files
committed
add toStrictByteString to Data.ByteString.Builder
1 parent 6641404 commit 67bc94d

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* [Remove `zipWith` rewrite rule](https://github.com/haskell/bytestring/pull/387)
66
* [`ShortByteString` is now a wrapper over boxed `Data.Array.Byte.ByteArray` instead of unboxed `ByteArray#` directly](https://github.com/haskell/bytestring/pull/410)
77
* [`fromListN` from `instance IsList ShortByteString` throws an exception if the first argument does not match the length of the second instead of silent ignore](https://github.com/haskell/bytestring/pull/410)
8+
* [Add `toStrictByteString` to `Data.ByteString.Builder`](https://github.com/haskell/bytestring/pull/589)
89

910
[0.12.0.0]: https://github.com/haskell/bytestring/compare/0.11.4.0...0.12.0.0
1011

Data/ByteString/Builder.hs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ module Data.ByteString.Builder
189189
-- cases. See "Data.ByteString.Builder.Extra", for information
190190
-- about fine-tuning them.
191191
, toLazyByteString
192+
, toStrictByteString
192193
, hPutBuilder
193194
, writeFile
194195

@@ -260,6 +261,7 @@ import Prelude hiding (writeFile)
260261

261262
import Data.ByteString.Builder.Internal
262263
import qualified Data.ByteString.Builder.Prim as P
264+
import qualified Data.ByteString.Internal as S
263265
import qualified Data.ByteString.Lazy.Internal as L
264266
import Data.ByteString.Builder.ASCII
265267
import Data.ByteString.Builder.RealFloat
@@ -278,6 +280,14 @@ toLazyByteString :: Builder -> L.ByteString
278280
toLazyByteString = toLazyByteStringWith
279281
(safeStrategy L.smallChunkSize L.defaultChunkSize) L.Empty
280282

283+
-- | Execute a 'Builder' and pack the resulting chunks into a strict 'S.ByteString'.
284+
--
285+
-- @'toStrictByteString' = 'L.toStrict' . 'toLazyByteString'@
286+
--
287+
{-# INLINABLE toStrictByteString #-}
288+
toStrictByteString :: Builder -> S.ByteString
289+
toStrictByteString = L.toStrict . toLazyByteString
290+
281291
{- Not yet stable enough.
282292
See note on 'hPut' in Data.ByteString.Builder.Internal
283293
-}

0 commit comments

Comments
 (0)