@@ -433,8 +433,8 @@ srp6GroupSize groupId =
433433 Utility
434434-------------------------------------------------------------------------------}
435435
436- -- | A version of 'BS.create' that determines the size of the byte string based
437- -- on an argument 'DLGroupName'.
436+ -- | Like 'createWithSize', but we determine the maximum size of the byte string
437+ -- based on an argument 'DLGroupName'.
438438createWithGroupSize ::
439439 DLGroupName
440440 -> (Ptr Word8 -> Ptr CSize -> IO () )
@@ -443,21 +443,27 @@ createWithGroupSize groupId k = do
443443 sz <- srp6GroupSize groupId
444444 createWithSize sz k
445445
446- -- | A version of 'BS.create' that also creates a pointer for the size of the
447- -- byte string.
446+ -- | Given the maximum size needed and a function to make the contents of a
447+ -- 'ByteString', 'createWithSize' makes the 'ByteString'.
448+ --
449+ -- The generating function is required to write the actual final size (<= the
450+ -- maximum size) to the 'CSize' pointer, and the resulting byte array is
451+ -- reallocated to this size.
452+ --
453+ -- NOTE: this is based on 'BS.createAndTrim'.
448454createWithSize ::
449455 Int
450456 -> (Ptr Word8 -> Ptr CSize -> IO () )
451457 -> IO ByteString
452458createWithSize sz k =
453- BS. createUptoN sz $ \ bytesPtr ->
459+ BS. createAndTrim sz $ \ bytesPtr ->
454460 alloca $ \ lenPtr -> do
455461 poke lenPtr (fromIntegral sz)
456462 k bytesPtr lenPtr
457463 fromIntegral <$> peek lenPtr
458464
459- -- | A version of 'BS.createUptoN'' that determines the size of the byte string
460- -- based on an argument 'DLGroupName' .
465+ -- | Like 'createWithGroupSize', but also returns an additional value created by
466+ -- the action .
461467createWithGroupSize' ::
462468 DLGroupName
463469 -> (Ptr Word8 -> Ptr CSize -> IO a )
@@ -466,16 +472,18 @@ createWithGroupSize' groupId k = do
466472 sz <- srp6GroupSize groupId
467473 createWithSize' sz k
468474
469- -- | A version of 'BS.createUptoN'' that also creates a pointer for the size of
470- -- the byte string.
475+ -- | Like 'createWithSize', but also returns an additional value created by the
476+ -- action.
477+ --
478+ -- NOTE: this is based on 'BS.createAndTrim''.
471479createWithSize' ::
472480 Int
473481 -> (Ptr Word8 -> Ptr CSize -> IO a )
474482 -> IO (ByteString , a )
475483createWithSize' sz k =
476- BS. createUptoN ' sz $ \ bytesPtr ->
484+ BS. createAndTrim ' sz $ \ bytesPtr ->
477485 alloca $ \ lenPtr -> do
478486 poke lenPtr (fromIntegral sz)
479487 x <- k bytesPtr lenPtr
480488 sz' <- fromIntegral <$> peek lenPtr
481- pure (sz', x)
489+ pure (0 , sz', x)
0 commit comments