Skip to content

add toStrictByteString #589

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/589)

[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