Skip to content

Commit 02fd9c1

Browse files
author
Juergen Gmeiner
committed
additional Int53 api using Number purescript-node#37
1 parent d18a01f commit 02fd9c1

File tree

3 files changed

+77
-4
lines changed

3 files changed

+77
-4
lines changed

src/Node/FS.purs

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module Node.FS
99
, BufferOffset(..)
1010
, ByteCount(..)
1111
, FilePosition(..)
12+
, FilePositionInt53(..)
1213
, fileFlagsToNode
1314
) where
1415

@@ -64,6 +65,8 @@ type BufferLength = Int
6465
type BufferOffset = Int
6566
type ByteCount = Int
6667

68+
type FilePositionInt53 = Number
69+
6770
-- | Symlink varieties.
6871
data SymlinkType = FileLink | DirLink | JunctionLink
6972

src/Node/FS/Async.purs

+36-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ module Node.FS.Async
2525
, exists
2626
, fdOpen
2727
, fdRead
28+
, fdReadInt53
2829
, fdNext
2930
, fdWrite
31+
, fdWriteInt53
3032
, fdAppend
3133
, fdClose
3234
) where
@@ -46,8 +48,8 @@ import Data.Nullable (Nullable, toNullable)
4648
import Node.Buffer (Buffer(), BUFFER(), size)
4749
import Data.Int (round)
4850
import Node.Encoding (Encoding)
49-
import Node.FS (FS, FileDescriptor, ByteCount, FilePosition, BufferLength,
50-
BufferOffset, FileMode, FileFlags, SymlinkType,
51+
import Node.FS (FS, FileDescriptor, ByteCount, FilePosition, FilePositionInt53,
52+
BufferLength, BufferOffset, FileMode, FileFlags, SymlinkType,
5153
fileFlagsToNode, symlinkTypeToNode)
5254
import Node.FS.Stats (StatsObj, Stats(..))
5355
import Node.Path (FilePath())
@@ -91,6 +93,13 @@ fs ::
9193
}
9294
fs = unsafeRequireFS
9395

96+
fsInt53 ::
97+
{ read :: Fn6 FileDescriptor Buffer BufferOffset BufferLength (Nullable FilePositionInt53) (JSCallback ByteCount) Unit
98+
, write :: Fn6 FileDescriptor Buffer BufferOffset BufferLength (Nullable FilePositionInt53) (JSCallback ByteCount) Unit
99+
}
100+
fsInt53 = unsafeRequireFS
101+
102+
94103
-- | Type synonym for callback functions.
95104
type Callback eff a = Either Error a -> Eff (fs :: FS | eff) Unit
96105

@@ -324,6 +333,18 @@ fdRead :: forall eff.
324333
-> Eff (buffer :: BUFFER, fs :: FS | eff) Unit
325334
fdRead fd buff off len pos cb = mkEff $ \_ -> runFn6 fs.read fd buff off len (toNullable pos) (handleCallback cb)
326335

336+
-- | Read from a file asynchronously. See the [Node Documentation](https://nodejs.org/api/fs.html#fs_fs_read_fd_buffer_offset_length_position_callback)
337+
-- | for details.
338+
fdReadInt53 :: forall eff.
339+
FileDescriptor
340+
-> Buffer
341+
-> BufferOffset
342+
-> BufferLength
343+
-> Maybe FilePositionInt53
344+
-> Callback (buffer :: BUFFER | eff) ByteCount
345+
-> Eff (buffer :: BUFFER, fs :: FS | eff) Unit
346+
fdReadInt53 fd buff off len pos cb = mkEff $ \_ -> runFn6 fsInt53.read fd buff off len (toNullable pos) (handleCallback cb)
347+
327348
-- | Convenience function to fill the whole buffer from the current
328349
-- | file position.
329350
fdNext :: forall eff.
@@ -347,6 +368,19 @@ fdWrite :: forall eff.
347368
-> Eff (buffer :: BUFFER, fs :: FS | eff) Unit
348369
fdWrite fd buff off len pos cb = mkEff $ \_ -> runFn6 fs.write fd buff off len (toNullable pos) (handleCallback cb)
349370

371+
-- | Write to a file asynchronously. See the [Node Documentation](https://nodejs.org/api/fs.html#fs_fs_write_fd_buffer_offset_length_position_callback)
372+
-- | for details.
373+
fdWriteInt53 :: forall eff.
374+
FileDescriptor
375+
-> Buffer
376+
-> BufferOffset
377+
-> BufferLength
378+
-> Maybe FilePositionInt53
379+
-> Callback (buffer :: BUFFER | eff) ByteCount
380+
-> Eff (buffer :: BUFFER, fs :: FS | eff) Unit
381+
fdWriteInt53 fd buff off len pos cb = mkEff $ \_ -> runFn6 fsInt53.write fd buff off len (toNullable pos) (handleCallback cb)
382+
383+
350384
-- | Convenience function to append the whole buffer to the current
351385
-- | file position.
352386
fdAppend :: forall eff.

src/Node/FS/Sync.purs

+38-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ module Node.FS.Sync
2424
, exists
2525
, fdOpen
2626
, fdRead
27+
, fdReadInt53
2728
, fdNext
2829
, fdWrite
30+
, fdWriteInt53
2931
, fdAppend
3032
, fdFlush
3133
, fdClose
@@ -45,8 +47,8 @@ import Data.Maybe (Maybe(..))
4547
import Node.Buffer (Buffer(), BUFFER(), size)
4648
import Node.Encoding (Encoding)
4749

48-
import Node.FS (FS, FileDescriptor, ByteCount, FilePosition, BufferLength,
49-
BufferOffset, FileMode, FileFlags, SymlinkType,
50+
import Node.FS (FS, FileDescriptor, ByteCount, FilePosition, FilePositionInt53,
51+
BufferLength, BufferOffset, FileMode, FileFlags, SymlinkType,
5052
fileFlagsToNode, symlinkTypeToNode)
5153
import Node.FS.Stats (StatsObj, Stats(..))
5254
import Node.Path (FilePath())
@@ -80,6 +82,12 @@ fs ::
8082
}
8183
fs = unsafeRequireFS
8284

85+
fsInt53 ::
86+
{ readSync :: Fn5 FileDescriptor Buffer BufferOffset BufferLength (Nullable FilePositionInt53) ByteCount
87+
, writeSync :: Fn5 FileDescriptor Buffer BufferOffset BufferLength (Nullable FilePositionInt53) ByteCount
88+
}
89+
fsInt53 = unsafeRequireFS
90+
8391
-- | Renames a file.
8492
rename :: forall eff. FilePath
8593
-> FilePath
@@ -286,6 +294,20 @@ fdRead :: forall eff.
286294
fdRead fd buff off len pos =
287295
mkEff $ \_ -> runFn5 fs.readSync fd buff off len (toNullable pos)
288296

297+
-- | Read from a file synchronously. See the [Node documentation](http://nodejs.org/api/fs.html#fs_fs_readsync_fd_buffer_offset_length_position)
298+
-- | for details.
299+
-- |
300+
-- | This version takes a position argument that is not restricted to 2GB
301+
fdReadInt53 :: forall eff.
302+
FileDescriptor
303+
-> Buffer
304+
-> BufferOffset
305+
-> BufferLength
306+
-> Maybe FilePositionInt53
307+
-> Eff (buffer :: BUFFER, exception :: EXCEPTION, fs :: FS | eff) ByteCount
308+
fdReadInt53 fd buff off len pos =
309+
mkEff $ \_ -> runFn5 fsInt53.readSync fd buff off len (toNullable pos)
310+
289311
-- | Convenience function to fill the whole buffer from the current
290312
-- | file position.
291313
fdNext :: forall eff.
@@ -308,6 +330,20 @@ fdWrite :: forall eff.
308330
fdWrite fd buff off len pos =
309331
mkEff $ \_ -> runFn5 fs.writeSync fd buff off len (toNullable pos)
310332

333+
-- | Write to a file synchronously. See the [Node documentation](http://nodejs.org/api/fs.html#fs_fs_writesync_fd_buffer_offset_length_position)
334+
-- | for details.
335+
-- |
336+
-- | This version takes a position argument that is not restricted to 2GB
337+
fdWriteInt53 :: forall eff.
338+
FileDescriptor
339+
-> Buffer
340+
-> BufferOffset
341+
-> BufferLength
342+
-> Maybe FilePositionInt53
343+
-> Eff (buffer :: BUFFER, exception :: EXCEPTION, fs :: FS | eff) ByteCount
344+
fdWriteInt53 fd buff off len pos =
345+
mkEff $ \_ -> runFn5 fsInt53.writeSync fd buff off len (toNullable pos)
346+
311347
-- | Convenience function to append the whole buffer to the current
312348
-- | file position.
313349
fdAppend :: forall eff.

0 commit comments

Comments
 (0)