forked from purescript-contrib/purescript-arraybuffer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayBuffer.purs
More file actions
32 lines (23 loc) · 1.31 KB
/
ArrayBuffer.purs
File metadata and controls
32 lines (23 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
module Data.ArrayBuffer ( ARRAY_BUFFER()
, create
, byteLength
, slice
, fromArray
, fromString
) where
import Control.Monad.Eff (kind Effect, Eff)
import Data.Function.Uncurried (Fn3, runFn3)
import Data.ArrayBuffer.Types (ArrayBuffer, ByteOffset, ByteLength)
foreign import data ARRAY_BUFFER :: Effect
-- | Create an `ArrayBuffer` with the given capacity.
foreign import create :: forall e. ByteLength -> Eff (arrayBuffer :: ARRAY_BUFFER | e) ArrayBuffer
-- | Represents the length of an `ArrayBuffer` in bytes.
foreign import byteLength :: ArrayBuffer -> ByteLength
foreign import sliceImpl :: forall e. Fn3 ByteOffset ByteOffset ArrayBuffer (Eff (arrayBuffer :: ARRAY_BUFFER | e) ArrayBuffer)
-- | Returns a new `ArrayBuffer` whose contents are a copy of this ArrayBuffer's bytes from begin, inclusive, up to end, exclusive.
slice :: forall e. ByteOffset -> ByteOffset -> ArrayBuffer -> Eff (arrayBuffer :: ARRAY_BUFFER | e) ArrayBuffer
slice = runFn3 sliceImpl
-- | Convert an array into an `ArrayBuffer` representation.
foreign import fromArray :: Array Number -> ArrayBuffer
-- | Convert a string into an `ArrayBuffer` representation.
foreign import fromString :: String -> ArrayBuffer