on 2ca80e7 help sign in
649 lines 22 kB history raw
1#include "inline.hs"
3-- |
4-- Module : Streamly.Internal.Network.Socket
5-- Copyright : (c) 2018 Composewell Technologies
6--
7-- License : BSD3
8-- Maintainer : streamly@composewell.com
9-- Stability : experimental
10-- Portability : GHC
11--
12module Streamly.Internal.Network.Socket
13 (
14 SockSpec (..)
15 -- * Use a socket
16 , forSocketM
17 , withSocket
19 -- * Accept connections
20 , accept
21 , connections
22 , connect
23 , connectFrom
25 -- * Read from connection
26 , read
27 , readWith
28 -- , readUtf8
29 -- , readLines
30 -- , readFrames
31 -- , readByChunks
33 -- -- * Array Read
34 -- , readArrayUpto
35 -- , readChunksUpto
36 , readChunk
37 , readChunks
38 , readChunksWith
40 , toChunksWith
41 , toChunks
42 , toBytes
44 -- * Write to connection
45 , write
46 -- , writeUtf8
47 -- , writeUtf8ByLines
48 -- , writeByFrames
49 , writeWith
50 , writeMaybesWith
52 , putChunks
53 , putBytesWith
54 , putBytes
56 -- -- * Array Write
57 , writeChunk
58 , writeChunks
59 , writeChunksWith
61 -- reading/writing datagrams
63 -- * Deprecated
64 , readWithBufferOf
65 , readChunksWithBufferOf
66 , writeWithBufferOf
67 , writeChunksWithBufferOf
68 )
69where
71import Control.Concurrent (threadWaitWrite, rtsSupportsBoundThreads)
72import Control.Exception (onException)
73import Control.Monad.Catch (MonadCatch, finally, MonadMask)
74import Control.Monad.IO.Class (MonadIO(..))
75import Control.Monad (forM_, when)
76import Data.Maybe (isNothing, fromJust)
77import Data.Word (Word8)
78import Foreign.Ptr (plusPtr, Ptr, castPtr)
79import Streamly.Internal.Data.Unboxed (Unboxed)
80import Network.Socket
81 (Socket, SocketOption(..), Family(..), SockAddr(..),
82 ProtocolNumber, withSocketsDo, SocketType(..), socket, bind,
83 setSocketOption, sendBuf, recvBuf)
84#if MIN_VERSION_network(3,1,0)
85import Network.Socket (withFdSocket)
86#else
87import Network.Socket (fdSocket)
88#endif
89import Prelude hiding (read)
91import qualified Network.Socket as Net
93import Streamly.Internal.Control.Concurrent (MonadAsync)
94import Streamly.Internal.Data.Array.Unboxed.Type (Array(..))
95import Streamly.Internal.Data.Array.Stream.Foreign (lpackArraysChunksOf)
96import Streamly.Internal.Data.Fold (Fold)
97import Streamly.Internal.Data.Stream.IsStream.Type
98 (IsStream, mkStream, fromStreamD)
99import Streamly.Internal.Data.Stream.Type (Stream)
100import Streamly.Internal.Data.Unfold.Type (Unfold(..))
101-- import Streamly.String (encodeUtf8, decodeUtf8, foldLines)
102import Streamly.Internal.System.IO (defaultChunkSize)
104import qualified Streamly.Data.Array.Unboxed as A (read, length, writeN)
105import qualified Streamly.Data.Fold as FL
106import qualified Streamly.Internal.Data.Array.Unboxed.Type as A
107 (unsafeFreeze, asPtrUnsafe, byteLength, writeNUnsafe)
108import qualified Streamly.Internal.Data.Array.Unboxed.Mut as MArray
109 (Array(..), newPinnedArrayBytes, asPtrUnsafe)
110import qualified Streamly.Internal.Data.Array.Stream.Foreign as AS
111import qualified Streamly.Internal.Data.Stream.IsStream as S
112import qualified Streamly.Internal.Data.Stream.StreamD.Type as D
113 (Stream(..), Step(..))
114import qualified Streamly.Data.Unfold as UF
115import qualified Streamly.Internal.Data.Unfold as UF (first, map)
117-- | @'forSocketM' action socket@ runs the monadic computation @action@ passing
118-- the socket handle to it. The handle will be closed on exit from
119-- 'forSocketM', whether by normal termination or by raising an exception. If
120-- closing the handle raises an exception, then this exception will be raised
121-- by 'forSocketM' rather than any exception raised by 'action'.
122--
123-- @since 0.8.0
124{-# INLINE forSocketM #-}
125forSocketM :: (MonadMask m, MonadIO m) => (Socket -> m ()) -> Socket -> m ()
126forSocketM f sk = finally (f sk) (liftIO (Net.close sk))
128-- | Like 'forSocketM' but runs a streaming computation instead of a monadic
129-- computation.
130--
131-- /Inhibits stream fusion/
132--
133-- /Internal/
134{-# INLINE withSocket #-}
135withSocket :: (IsStream t, MonadAsync m, MonadCatch m)
136 => Socket -> (Socket -> t m a) -> t m a
137withSocket sk f = S.finally (liftIO $ Net.close sk) (f sk)
139-------------------------------------------------------------------------------
140-- Accept (Unfolds)
141-------------------------------------------------------------------------------
143-- XXX Protocol specific socket options should be separated from socket level
144-- options.
145--
146-- | Specify the socket protocol details.
147data SockSpec = SockSpec
148 {
149 sockFamily :: !Family
150 , sockType :: !SocketType
151 , sockProto :: !ProtocolNumber
152 , sockOpts :: ![(SocketOption, Int)]
153 }
155initListener :: Int -> SockSpec -> SockAddr -> IO Socket
156initListener listenQLen SockSpec{..} addr =
157 withSocketsDo $ do
158 sock <- socket sockFamily sockType sockProto
159 use sock `onException` Net.close sock
160 return sock
162 where
164 use sock = do
165 mapM_ (\(opt, val) -> setSocketOption sock opt val) sockOpts
166 bind sock addr
167 Net.listen sock listenQLen
169{-# INLINE listenTuples #-}
170listenTuples :: MonadIO m
171 => Unfold m (Int, SockSpec, SockAddr) (Socket, SockAddr)
172listenTuples = Unfold step inject
173 where
174 inject (listenQLen, spec, addr) =
175 liftIO $ initListener listenQLen spec addr
177 step listener = do
178 r <- liftIO (Net.accept listener `onException` Net.close listener)
179 return $ D.Yield r listener
181-- | Unfold a three tuple @(listenQLen, spec, addr)@ into a stream of connected
182-- protocol sockets corresponding to incoming connections. @listenQLen@ is the
183-- maximum number of pending connections in the backlog. @spec@ is the socket
184-- protocol and options specification and @addr@ is the protocol address where
185-- the server listens for incoming connections.
186--
187-- @since 0.7.0
188{-# INLINE accept #-}
189accept :: MonadIO m => Unfold m (Int, SockSpec, SockAddr) Socket
190accept = UF.map fst listenTuples
192{-# INLINE connectCommon #-}
193connectCommon :: SockSpec -> Maybe SockAddr -> SockAddr -> IO Socket
194connectCommon SockSpec{..} local remote = withSocketsDo $ do
195 sock <- socket sockFamily sockType sockProto
196 use sock `onException` Net.close sock
197 return sock
199 where
201 use sock = do
202 mapM_ (\(opt, val) -> setSocketOption sock opt val) sockOpts
203 forM_ local (bind sock)
204 Net.connect sock remote
206-- | Connect to a remote host using the given socket specification and remote
207-- address. Returns a connected socket or throws an exception.
208--
209-- /Pre-release/
210--
211{-# INLINE connect #-}
212connect :: SockSpec -> SockAddr -> IO Socket
213connect spec = connectCommon spec Nothing
215-- | Connect to a remote host using the given socket specification, a local
216-- address to bind to and a remote address to connect to. Returns a connected
217-- socket or throws an exception.
218--
219-- /Pre-release/
220--
221{-# INLINE connectFrom #-}
222connectFrom :: SockSpec -> SockAddr -> SockAddr -> IO Socket
223connectFrom spec local = connectCommon spec (Just local)
225-------------------------------------------------------------------------------
226-- Listen (Streams)
227-------------------------------------------------------------------------------
229{-# INLINE recvConnectionTuplesWith #-}
230recvConnectionTuplesWith :: MonadAsync m
231 => Int -> SockSpec -> SockAddr -> Stream m (Socket, SockAddr)
232recvConnectionTuplesWith tcpListenQ spec addr = S.unfoldrM step Nothing
233 where
234 step Nothing = do
235 listener <- liftIO $ initListener tcpListenQ spec addr
236 r <- liftIO (Net.accept listener `onException` Net.close listener)
237 return $ Just (r, Just listener)
239 step (Just listener) = do
240 r <- liftIO (Net.accept listener `onException` Net.close listener)
241 return $ Just (r, Just listener)
243-- | Start a TCP stream server that listens for connections on the supplied
244-- server address specification (address family, local interface IP address and
245-- port). The server generates a stream of connected sockets. The first
246-- argument is the maximum number of pending connections in the backlog.
247--
248-- /Pre-release/
249{-# INLINE connections #-}
250connections :: MonadAsync m => Int -> SockSpec -> SockAddr -> Stream m Socket
251connections tcpListenQ spec addr =
252 fst <$> recvConnectionTuplesWith tcpListenQ spec addr
254-------------------------------------------------------------------------------
255-- Array IO (Input)
256-------------------------------------------------------------------------------
258{-# INLINABLE readArrayUptoWith #-}
259readArrayUptoWith
260 :: (h -> Ptr Word8 -> Int -> IO Int)
261 -> Int
262 -> h
263 -> IO (Array Word8)
264readArrayUptoWith f size h = do
265 arr <- MArray.newPinnedArrayBytes size
266 -- ptr <- mallocPlainForeignPtrAlignedBytes size (alignment (undefined :: Word8))
267 MArray.asPtrUnsafe arr $ \p -> do
268 n <- f h p size
269 let v = A.unsafeFreeze
270 $ arr { MArray.arrEnd = n, MArray.arrBound = size }
272 -- XXX shrink only if the diff is significant
273 -- A.shrinkToFit v
274 return v
276-- | Read a byte array from a file handle up to a maximum of the requested
277-- size. If no data is available on the handle it blocks until some data
278-- becomes available. If data is available then it immediately returns that
279-- data without blocking.
280--
281-- @since 0.8.0
282{-# INLINABLE readChunk #-}
283readChunk :: Int -> Socket -> IO (Array Word8)
284readChunk = readArrayUptoWith recvBuf
286-------------------------------------------------------------------------------
287-- Array IO (output)
288-------------------------------------------------------------------------------
290waitWhen0 :: Int -> Socket -> IO ()
291waitWhen0 0 s = when rtsSupportsBoundThreads $
292#if MIN_VERSION_network(3,1,0)
293 withFdSocket s $ \fd -> threadWaitWrite $ fromIntegral fd
294#elif MIN_VERSION_network(3,0,0)
295 fdSocket s >>= threadWaitWrite . fromIntegral
296#else
297 let fd = fdSocket s in threadWaitWrite $ fromIntegral fd
298#endif
299waitWhen0 _ _ = return ()
301sendAll :: Socket -> Ptr Word8 -> Int -> IO ()
302sendAll _ _ len | len <= 0 = return ()
303sendAll s p len = do
304 sent <- sendBuf s p len
305 waitWhen0 sent s
306 -- assert (sent <= len)
307 when (sent >= 0) $ sendAll s (p `plusPtr` sent) (len - sent)
309{-# INLINABLE writeArrayWith #-}
310writeArrayWith :: Unboxed a
311 => (h -> Ptr Word8 -> Int -> IO ())
312 -> h
313 -> Array a
314 -> IO ()
315writeArrayWith _ _ arr | A.length arr == 0 = return ()
316writeArrayWith f h arr = A.asPtrUnsafe arr $ \ptr -> f h (castPtr ptr) aLen
318 where
320 aLen = A.byteLength arr
322-- | Write an Array to a file handle.
323--
324-- @since 0.8.0
325{-# INLINABLE writeChunk #-}
326writeChunk :: Unboxed a => Socket -> Array a -> IO ()
327writeChunk = writeArrayWith sendAll
329-------------------------------------------------------------------------------
330-- Stream of Arrays IO
331-------------------------------------------------------------------------------
333{-# INLINE _readChunksUptoWith #-}
334_readChunksUptoWith :: (IsStream t, MonadIO m)
335 => (Int -> h -> IO (Array Word8))
336 -> Int -> h -> t m (Array Word8)
337_readChunksUptoWith f size h = go
338 where
339 -- XXX use cons/nil instead
340 go = mkStream $ \_ yld _ stp -> do
341 arr <- liftIO $ f size h
342 if A.length arr == 0
343 then stp
344 else yld arr go
346-- | @toChunksWith size h@ reads a stream of arrays from file handle @h@.
347-- The maximum size of a single array is limited to @size@.
348-- 'fromHandleArraysUpto' ignores the prevailing 'TextEncoding' and 'NewlineMode'
349-- on the 'Handle'.
350{-# INLINE_NORMAL toChunksWith #-}
351toChunksWith :: (IsStream t, MonadIO m)
352 => Int -> Socket -> t m (Array Word8)
353-- toChunksWith = _readChunksUptoWith readChunk
354toChunksWith size h = fromStreamD (D.Stream step ())
355 where
356 {-# INLINE_LATE step #-}
357 step _ _ = do
358 arr <- liftIO $ readChunk size h
359 return $
360 case A.length arr of
361 0 -> D.Stop
362 _ -> D.Yield arr ()
364-- XXX read 'Array a' instead of Word8
365--
366-- | @toChunks h@ reads a stream of arrays from socket handle @h@.
367-- The maximum size of a single array is limited to @defaultChunkSize@.
368--
369-- @since 0.7.0
370{-# INLINE toChunks #-}
371toChunks :: (IsStream t, MonadIO m) => Socket -> t m (Array Word8)
372toChunks = toChunksWith defaultChunkSize
374-- | Unfold the tuple @(bufsize, socket)@ into a stream of 'Word8' arrays.
375-- Read requests to the socket are performed using a buffer of size @bufsize@.
376-- The size of an array in the resulting stream is always less than or equal to
377-- @bufsize@.
378--
379-- @since 0.9.0
380{-# INLINE_NORMAL readChunksWith #-}
381readChunksWith :: MonadIO m => Unfold m (Int, Socket) (Array Word8)
382readChunksWith = Unfold step return
383 where
384 {-# INLINE_LATE step #-}
385 step (size, h) = do
386 arr <- liftIO $ readChunk size h
387 return $
388 case A.length arr of
389 0 -> D.Stop
390 _ -> D.Yield arr (size, h)
392-- | Same as 'readChunksWith'
393--
394-- @since 0.7.0
395{-# DEPRECATED readChunksWithBufferOf "Please use 'readChunksWith' instead" #-}
396{-# INLINE_NORMAL readChunksWithBufferOf #-}
397readChunksWithBufferOf :: MonadIO m => Unfold m (Int, Socket) (Array Word8)
398readChunksWithBufferOf = readChunksWith
400-- | Unfolds a socket into a stream of 'Word8' arrays. Requests to the socket
401-- are performed using a buffer of size
402-- 'Streamly.Internal.Data.Array.Unboxed.Type.defaultChunkSize'. The
403-- size of arrays in the resulting stream are therefore less than or equal to
404-- 'Streamly.Internal.Data.Array.Unboxed.Type.defaultChunkSize'.
405--
406-- @since 0.7.0
407{-# INLINE readChunks #-}
408readChunks :: MonadIO m => Unfold m Socket (Array Word8)
409readChunks = UF.first defaultChunkSize readChunksWith
411-------------------------------------------------------------------------------
412-- Read File to Stream
413-------------------------------------------------------------------------------
415-- TODO for concurrent streams implement readahead IO. We can send multiple
416-- read requests at the same time. For serial case we can use async IO. We can
417-- also control the read throughput in mbps or IOPS.
419{-
420-- | @readWith bufsize handle@ reads a byte stream from a file
421-- handle, reads are performed in chunks of up to @bufsize@. The stream ends
422-- as soon as EOF is encountered.
423--
424{-# INLINE readWith #-}
425readWith :: (IsStream t, MonadIO m) => Int -> Handle -> t m Word8
426readWith chunkSize h = A.flattenArrays $ readChunksUpto chunkSize h
427-}
429-- TODO
430-- read :: (IsStream t, MonadIO m, Unboxed a) => Handle -> t m a
431--
432-- > read = 'readByChunks' defaultChunkSize
433-- | Generate a stream of elements of the given type from a socket. The
434-- stream ends when EOF is encountered.
435--
436-- @since 0.7.0
437{-# INLINE toBytes #-}
438toBytes :: (IsStream t, MonadIO m) => Socket -> t m Word8
439toBytes = AS.concat . toChunks
441-- | Unfolds the tuple @(bufsize, socket)@ into a byte stream, read requests
442-- to the socket are performed using buffers of @bufsize@.
443--
444-- @since 0.9.0
445{-# INLINE readWith #-}
446readWith :: MonadIO m => Unfold m (Int, Socket) Word8
447readWith = UF.many A.read readChunksWith
449-- | Same as 'readWith'
450--
451-- @since 0.7.0
452{-# DEPRECATED readWithBufferOf "Please use 'readWith' instead" #-}
453{-# INLINE readWithBufferOf #-}
454readWithBufferOf :: MonadIO m => Unfold m (Int, Socket) Word8
455readWithBufferOf = readWith
457-- | Unfolds a 'Socket' into a byte stream. IO requests to the socket are
458-- performed in sizes of
459-- 'Streamly.Internal.Data.Array.Unboxed.Type.defaultChunkSize'.
460--
461-- @since 0.7.0
462{-# INLINE read #-}
463read :: MonadIO m => Unfold m Socket Word8
464read = UF.first defaultChunkSize readWith
466-------------------------------------------------------------------------------
467-- Writing
468-------------------------------------------------------------------------------
470-- | Write a stream of arrays to a handle.
471--
472-- @since 0.7.0
473{-# INLINE putChunks #-}
474putChunks :: (MonadIO m, Unboxed a)
475 => Socket -> Stream m (Array a) -> m ()
476putChunks h = S.mapM_ (liftIO . writeChunk h)
478-- | Write a stream of arrays to a socket. Each array in the stream is written
479-- to the socket as a separate IO request.
480--
481-- @since 0.7.0
482{-# INLINE writeChunks #-}
483writeChunks :: (MonadIO m, Unboxed a) => Socket -> Fold m (Array a) ()
484writeChunks h = FL.drainBy (liftIO . writeChunk h)
486-- | @writeChunksWith bufsize socket@ writes a stream of arrays to
487-- @socket@ after coalescing the adjacent arrays in chunks of @bufsize@.
488-- Multiple arrays are coalesed as long as the total size remains below the
489-- specified size. It never splits an array, if a single array is bigger than
490-- the specified size it emitted as it is.
491--
492-- @since 0.9.0
493{-# INLINE writeChunksWith #-}
494writeChunksWith :: (MonadIO m, Unboxed a)
495 => Int -> Socket -> Fold m (Array a) ()
496writeChunksWith n h = lpackArraysChunksOf n (writeChunks h)
498-- | Same as 'writeChunksWith'
499--
500-- @since 0.7.0
501{-# DEPRECATED writeChunksWithBufferOf "Please use 'writeChunksWith' instead" #-}
502{-# INLINE writeChunksWithBufferOf #-}
503writeChunksWithBufferOf :: (MonadIO m, Unboxed a)
504 => Int -> Socket -> Fold m (Array a) ()
505writeChunksWithBufferOf = writeChunksWith
507-- GHC buffer size dEFAULT_FD_BUFFER_SIZE=8192 bytes.
508--
509-- XXX test this
510-- Note that if you use a chunk size less than 8K (GHC's default buffer
511-- size) then you are advised to use 'NOBuffering' mode on the 'Handle' in case you
512-- do not want buffering to occur at GHC level as well. Same thing applies to
513-- writes as well.
515-- | Like 'write' but provides control over the write buffer. Output will
516-- be written to the IO device as soon as we collect the specified number of
517-- input elements.
518--
519-- @since 0.9.0
520{-# INLINE putBytesWith #-}
521putBytesWith :: MonadIO m => Int -> Socket -> Stream m Word8 -> m ()
522putBytesWith n h m = putChunks h $ AS.arraysOf n m
524-- | Write a byte stream to a socket. Accumulates the input in chunks of
525-- specified number of bytes before writing.
526--
527-- @since 0.9.0
528{-# INLINE writeWith #-}
529writeWith :: MonadIO m => Int -> Socket -> Fold m Word8 ()
530writeWith n h = FL.chunksOf n (A.writeNUnsafe n) (writeChunks h)
532-- | Same as 'writeWith'
533--
534-- @since 0.7.0
535{-# DEPRECATED writeWithBufferOf "Please use 'writeWith' instead" #-}
536{-# INLINE writeWithBufferOf #-}
537writeWithBufferOf :: MonadIO m => Int -> Socket -> Fold m Word8 ()
538writeWithBufferOf = writeWith
540-- | Write a stream of 'Maybe' values. Keep buffering the 'Just' values in an
541-- array. Write the array to the 'Handle' as soon as a 'Nothing' is encountered
542-- or the buffer size exceeds the specified limit.
543--
544-- /Pre-release/
545{-# INLINE writeMaybesWith #-}
546writeMaybesWith :: (MonadIO m )
547 => Int -> Socket -> Fold m (Maybe Word8) ()
548writeMaybesWith n h =
549 let writeNJusts = FL.lmap fromJust $ A.writeN n
550 writeOnNothing = FL.takeEndBy_ isNothing writeNJusts
551 in FL.many writeOnNothing (writeChunks h)
553-- > write = 'writeWith' defaultChunkSize
554--
555-- | Write a byte stream to a file handle. Combines the bytes in chunks of size
556-- up to 'defaultChunkSize' before writing. Note that the write behavior
557-- depends on the 'IOMode' and the current seek position of the handle.
558--
559-- @since 0.7.0
560{-# INLINE putBytes #-}
561putBytes :: MonadIO m => Socket -> Stream m Word8 -> m ()
562putBytes = putBytesWith defaultChunkSize
564-- | Write a byte stream to a socket. Accumulates the input in chunks of
565-- up to 'defaultChunkSize' bytes before writing.
566--
567-- @
568-- write = 'writeWith' 'defaultChunkSize'
569-- @
570--
571-- @since 0.7.0
572{-# INLINE write #-}
573write :: MonadIO m => Socket -> Fold m Word8 ()
574write = writeWith defaultChunkSize
576{-
577{-# INLINE write #-}
578write :: (MonadIO m, Unboxed a) => Handle -> Stream m a -> m ()
579write = toHandleWith defaultChunkSize
580-}
582-------------------------------------------------------------------------------
583-- IO with encoding/decoding Unicode characters
584-------------------------------------------------------------------------------
586{-
587-- |
588-- > readUtf8 = decodeUtf8 . read
589--
590-- Read a UTF8 encoded stream of unicode characters from a file handle.
591--
592-- @since 0.7.0
593{-# INLINE readUtf8 #-}
594readUtf8 :: (IsStream t, MonadIO m) => Handle -> t m Char
595readUtf8 = decodeUtf8 . read
597-- |
598-- > writeUtf8 h s = write h $ encodeUtf8 s
599--
600-- Encode a stream of unicode characters to UTF8 and write it to the given file
601-- handle. Default block buffering applies to the writes.
602--
603-- @since 0.7.0
604{-# INLINE writeUtf8 #-}
605writeUtf8 :: MonadIO m => Handle -> Stream m Char -> m ()
606writeUtf8 h s = write h $ encodeUtf8 s
608-- | Write a stream of unicode characters after encoding to UTF-8 in chunks
609-- separated by a linefeed character @'\n'@. If the size of the buffer exceeds
610-- @defaultChunkSize@ and a linefeed is not yet found, the buffer is written
611-- anyway. This is similar to writing to a 'Handle' with the 'LineBuffering'
612-- option.
613--
614-- @since 0.7.0
615{-# INLINE writeUtf8ByLines #-}
616writeUtf8ByLines :: (IsStream t, MonadIO m) => Handle -> t m Char -> m ()
617writeUtf8ByLines = undefined
619-- | Read UTF-8 lines from a file handle and apply the specified fold to each
620-- line. This is similar to reading a 'Handle' with the 'LineBuffering' option.
621--
622-- @since 0.7.0
623{-# INLINE readLines #-}
624readLines :: (IsStream t, MonadIO m) => Handle -> Fold m Char b -> t m b
625readLines h f = foldLines (readUtf8 h) f
627-------------------------------------------------------------------------------
628-- Framing on a sequence
629-------------------------------------------------------------------------------
631-- | Read a stream from a file handle and split it into frames delimited by
632-- the specified sequence of elements. The supplied fold is applied on each
633-- frame.
634--
635-- @since 0.7.0
636{-# INLINE readFrames #-}
637readFrames :: (IsStream t, MonadIO m, Unboxed a)
638 => Array a -> Handle -> Fold m a b -> t m b
639readFrames = undefined -- foldFrames . read
641-- | Write a stream to the given file handle buffering up to frames separated
642-- by the given sequence or up to a maximum of @defaultChunkSize@.
643--
644-- @since 0.7.0
645{-# INLINE writeByFrames #-}
646writeByFrames :: (IsStream t, MonadIO m, Unboxed a)
647 => Array a -> Handle -> t m a -> m ()
648writeByFrames = undefined
649-}