Skip to content

Commit 64dd83c

Browse files
committed
Add Streamly.FileSystem.FileIO
1 parent 31defa0 commit 64dd83c

4 files changed

Lines changed: 63 additions & 6 deletions

File tree

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
-- |
2+
-- Module : Streamly.FileSystem.FileIO
3+
-- Copyright : (c) 2019 Composewell Technologies
4+
--
5+
-- License : BSD3
6+
-- Maintainer : streamly@composewell.com
7+
-- Stability : pre-release
8+
-- Portability : GHC
9+
--
10+
-- Read and write streams and arrays to and from files specified by their paths
11+
-- in the file system. Unlike the handle based APIs which can have a read/write
12+
-- session consisting of multiple reads and writes to the handle, these APIs
13+
-- are one shot read or write APIs. These APIs open the file handle, perform
14+
-- the requested operation and close the handle. These are safer compared to
15+
-- the handle based APIs as there is no possibility of a file descriptor
16+
-- leakage.
17+
--
18+
-- >> import qualified Streamly.FileSystem.FileIO as File
19+
--
20+
module Streamly.FileSystem.FileIO
21+
(
22+
-- * Streaming IO
23+
-- | Stream data to or from a file or device sequentially. When reading,
24+
-- the stream is lazy and generated on-demand as the consumer consumes it.
25+
-- Read IO requests to the IO device are performed in chunks limited to a
26+
-- maximum size of 32KiB, this is referred to as @defaultChunkSize@ in the
27+
-- documentation. One IO request may or may not read the full
28+
-- chunk. If the whole stream is not consumed, it is possible that we may
29+
-- read slightly more from the IO device than what the consumer needed.
30+
-- Unless specified otherwise in the API, writes are collected into chunks
31+
-- of @defaultChunkSize@ before they are written to the IO device.
32+
33+
-- Streaming APIs work for all kind of devices, seekable or non-seekable;
34+
-- including disks, files, memory devices, terminals, pipes, sockets and
35+
-- fifos. While random access APIs work only for files or devices that have
36+
-- random access or seek capability for example disks, memory devices.
37+
-- Devices like terminals, pipes, sockets and fifos do not have random
38+
-- access capability.
39+
40+
-- ** File IO Using Handle
41+
withFile
42+
43+
-- ** Streams
44+
, read
45+
, readChunksWith
46+
, readChunks
47+
48+
-- ** Folds
49+
, write
50+
, writeWith
51+
, writeChunks
52+
)
53+
where
54+
55+
import Streamly.Internal.FileSystem.FileIO
56+
import Prelude hiding (read)

core/streamly-core.cabal

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ library
478478
, Streamly.Data.StreamK
479479
, Streamly.Data.Unfold
480480
, Streamly.FileSystem.DirIO
481-
, Streamly.FileSystem.File
481+
, Streamly.FileSystem.FileIO
482482
, Streamly.FileSystem.Handle
483483
, Streamly.FileSystem.Path
484484
, Streamly.FileSystem.Path.Seg
@@ -492,6 +492,7 @@ library
492492
, Streamly.Internal.FileSystem.File
493493
, Streamly.Internal.FileSystem.Dir
494494
, Streamly.FileSystem.Dir
495+
, Streamly.FileSystem.File
495496

496497
-- Deprecated in 0.2.0
497498
, Streamly.Internal.Data.MutArray.Stream

docs/User/Tutorials/quick-overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ import Data.Function ((&))
7070

7171
import qualified Streamly.Data.Fold as Fold
7272
import qualified Streamly.Data.Stream as Stream
73-
import qualified Streamly.FileSystem.File as File
73+
import qualified Streamly.FileSystem.FileIO as File
7474

7575
wcb :: String -> IO Int
7676
wcb file =

docs/User/Tutorials/replacing-other-packages.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@ distinction, file vs dir distinction or all four.
222222
The relevant modules in streamly are:
223223

224224
* `Streamly.Console.Stdio`
225-
* `Streamly.FileSystem.Dir`
226-
* `Streamly.FileSystem.File`
225+
* `Streamly.FileSystem.DirIO`
226+
* `Streamly.FileSystem.FileIO`
227227
* `Streamly.FileSystem.Handle`
228228
* `Streamly.Internal.FileSystem.Event`
229229
* `Streamly.Internal.FileSystem.Event.Linux`
@@ -232,12 +232,12 @@ The relevant modules in streamly are:
232232

233233
| Package | Streamly Module |
234234
|-----------------------|--------------------------------------------|
235-
| base/System.IO | Streamly.FileSystem.File,Handle |
235+
| base/System.IO | Streamly.FileSystem.FileIO,Handle |
236236
| filepath | Streamly.FileSystem.Path |
237237
| path | Streamly.Internal.FileSystem.Path.LocSeg |
238238
| path | Streamly.Internal.FileSystem.Path.FileDir |
239239
| path | Streamly.Internal.FileSystem.Path.Typed |
240-
| directory | Streamly.FileSystem.Dir |
240+
| directory | Streamly.FileSystem.DirIO |
241241
| fsnotify | Streamly.Internal.FileSystem.Event |
242242
| fsnotify | Streamly.Internal.FileSystem.Event.Windows |
243243
| hinotify | Streamly.Internal.FileSystem.Event.Linux |

0 commit comments

Comments
 (0)