Skip to content

Commit

Permalink
add toStrictByteString to Data.ByteString.Builder
Browse files Browse the repository at this point in the history
  • Loading branch information
fumieval committed May 30, 2023
1 parent 6641404 commit ae42860
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* [Remove `zipWith` rewrite rule](https://github.com/haskell/bytestring/pull/387)
* [`ShortByteString` is now a wrapper over boxed `Data.Array.Byte.ByteArray` instead of unboxed `ByteArray#` directly](https://github.com/haskell/bytestring/pull/410)
* [`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)
* [Add `toStrictByteString` to `Data.ByteString.Builder`](https://github.com/haskell/bytestring/pull/588)

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

Expand Down
10 changes: 10 additions & 0 deletions Data/ByteString/Builder.hs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ module Data.ByteString.Builder
-- cases. See "Data.ByteString.Builder.Extra", for information
-- about fine-tuning them.
, toLazyByteString
, toStrictByteString
, hPutBuilder
, writeFile

Expand Down Expand Up @@ -260,6 +261,7 @@ import Prelude hiding (writeFile)

import Data.ByteString.Builder.Internal
import qualified Data.ByteString.Builder.Prim as P
import qualified Data.ByteString.Internal as S
import qualified Data.ByteString.Lazy.Internal as L
import Data.ByteString.Builder.ASCII
import Data.ByteString.Builder.RealFloat
Expand All @@ -278,6 +280,14 @@ toLazyByteString :: Builder -> L.ByteString
toLazyByteString = toLazyByteStringWith
(safeStrategy L.smallChunkSize L.defaultChunkSize) L.Empty

-- | Execute a 'Builder' and pack the resulting chunks into a strict 'S.ByteString'.
--
-- @'toStrictByteString' = 'L.toStrict' . 'toLazyByteString'@
--
{-# INLINABLE toStrictByteString #-}
toStrictByteString :: Builder -> S.ByteString
toStrictByteString = L.toStrict . toLazyByteString

{- Not yet stable enough.
See note on 'hPut' in Data.ByteString.Builder.Internal
-}
Expand Down

0 comments on commit ae42860

Please sign in to comment.