Skip to content

Commit 1a934e1

Browse files
Use byteLength instead of length in putChunk
1 parent b484fe8 commit 1a934e1

2 files changed

Lines changed: 11 additions & 13 deletions

File tree

src/Streamly/Internal/FileSystem/File.hs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ where
8888
import Control.Monad.Catch (MonadCatch)
8989
import Control.Monad.IO.Class (MonadIO(..))
9090
import Data.Word (Word8)
91-
import Foreign.Storable (Storable(..))
9291
import System.IO (Handle, openFile, IOMode(..), hClose)
9392
import Prelude hiding (read)
9493

@@ -198,14 +197,14 @@ usingFile3 = UF.bracket before after
198197
--
199198
-- @since 0.7.0
200199
{-# INLINABLE putChunk #-}
201-
putChunk :: Storable a => FilePath -> Array a -> IO ()
200+
putChunk :: FilePath -> Array a -> IO ()
202201
putChunk file arr = SIO.withFile file WriteMode (`FH.putChunk` arr)
203202

204203
-- | append an array to a file.
205204
--
206205
-- @since 0.7.0
207206
{-# INLINABLE appendArray #-}
208-
appendArray :: Storable a => FilePath -> Array a -> IO ()
207+
appendArray :: FilePath -> Array a -> IO ()
209208
appendArray file arr = SIO.withFile file AppendMode (`FH.putChunk` arr)
210209

211210
-------------------------------------------------------------------------------
@@ -322,7 +321,7 @@ readShared = undefined
322321
-------------------------------------------------------------------------------
323322

324323
{-# INLINE fromChunksMode #-}
325-
fromChunksMode :: (MonadAsync m, MonadCatch m, Storable a)
324+
fromChunksMode :: (MonadAsync m, MonadCatch m)
326325
=> IOMode -> FilePath -> SerialT m (Array a) -> m ()
327326
fromChunksMode mode file xs = S.drain $
328327
withFile file mode (\h -> S.mapM (FH.putChunk h) xs)
@@ -331,7 +330,7 @@ fromChunksMode mode file xs = S.drain $
331330
--
332331
-- @since 0.7.0
333332
{-# INLINE fromChunks #-}
334-
fromChunks :: (MonadAsync m, MonadCatch m, Storable a)
333+
fromChunks :: (MonadAsync m, MonadCatch m)
335334
=> FilePath -> SerialT m (Array a) -> m ()
336335
fromChunks = fromChunksMode WriteMode
337336

@@ -376,7 +375,7 @@ write = toHandleWith A.defaultChunkSize
376375
--
377376
-- /Pre-release/
378377
{-# INLINE writeChunks #-}
379-
writeChunks :: (MonadIO m, MonadCatch m, Storable a)
378+
writeChunks :: (MonadIO m, MonadCatch m)
380379
=> FilePath -> Fold m (Array a) ()
381380
writeChunks path = Fold step initial extract
382381
where
@@ -422,7 +421,7 @@ write = writeWithBufferOf defaultChunkSize
422421
--
423422
-- @since 0.7.0
424423
{-# INLINE appendChunks #-}
425-
appendChunks :: (MonadAsync m, MonadCatch m, Storable a)
424+
appendChunks :: (MonadAsync m, MonadCatch m)
426425
=> FilePath -> SerialT m (Array a) -> m ()
427426
appendChunks = fromChunksMode AppendMode
428427

src/Streamly/Internal/FileSystem/Handle.hs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,8 @@ toBytes = AS.concat . toChunks
396396
--
397397
-- @since 0.8.1
398398
{-# INLINABLE putChunk #-}
399-
putChunk :: (MonadIO m, Storable a) => Handle -> Array a -> m ()
400-
putChunk _ arr | A.length arr == 0 = return ()
399+
putChunk :: MonadIO m => Handle -> Array a -> m ()
400+
putChunk _ arr | byteLength arr == 0 = return ()
401401
putChunk h Array{..} =
402402
liftIO $ hPutBuf h arrStart aLen >> touch arrContents
403403

@@ -420,8 +420,7 @@ putChunk h Array{..} =
420420
--
421421
-- @since 0.7.0
422422
{-# INLINE putChunks #-}
423-
putChunks :: (MonadIO m, Storable a)
424-
=> Handle -> SerialT m (Array a) -> m ()
423+
putChunks :: MonadIO m => Handle -> SerialT m (Array a) -> m ()
425424
putChunks h = S.mapM_ (putChunk h)
426425

427426
-- XXX AS.compact can be written idiomatically in terms of foldMany, just like
@@ -471,14 +470,14 @@ putBytes = putBytesWithBufferOf defaultChunkSize
471470
--
472471
-- @since 0.7.0
473472
{-# INLINE writeChunks #-}
474-
writeChunks :: (MonadIO m, Storable a) => Handle -> Fold m (Array a) ()
473+
writeChunks :: MonadIO m => Handle -> Fold m (Array a) ()
475474
writeChunks h = FL.drainBy (putChunk h)
476475

477476
-- | Like writeChunks but uses the experimental 'Refold' API.
478477
--
479478
-- /Internal/
480479
{-# INLINE consumeChunks #-}
481-
consumeChunks :: (MonadIO m, Storable a) => Refold m Handle (Array a) ()
480+
consumeChunks :: MonadIO m => Refold m Handle (Array a) ()
482481
consumeChunks = Refold.drainBy putChunk
483482

484483
-- XXX lpackArraysChunksOf should be written idiomatically

0 commit comments

Comments
 (0)