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
31 lines (24 loc) · 967 Bytes
/
ArrayBuffer.purs
File metadata and controls
31 lines (24 loc) · 967 Bytes
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.ArrayBuffer (
byteLength
, slice
--, isView
, eq
, notEq
, module Data.ArrayBuffer.Types
) where
import Prelude hiding (eq, notEq)
import Data.Function.Uncurried (Fn3, runFn3)
import Data.ArrayBuffer.TypedArray as TA
import Data.ArrayBuffer.Types (ArrayBuffer, ByteOffset, ByteLength)
-- | Represents the length of an `ArrayBuffer` in bytes.
foreign import byteLength :: ArrayBuffer -> ByteLength
foreign import sliceImpl :: Fn3 ByteOffset Int ArrayBuffer ArrayBuffer
-- | Returns a new `ArrayBuffer` whose contents are a copy of this ArrayBuffer's bytes from begin, inclusive, up to end, exclusive.
slice :: ByteOffset -> Int -> ArrayBuffer -> ArrayBuffer
slice = runFn3 sliceImpl
eq :: ArrayBuffer -> ArrayBuffer -> Boolean
eq ab1 ab2 =
byteLength ab1 == byteLength ab2
&& TA.fromArrayBuffer ab1 `TA.eq` (TA.fromArrayBuffer ab2 :: TA.Int32Array)
notEq :: ArrayBuffer -> ArrayBuffer -> Boolean
notEq ab1 ab2 = not $ ab1 `eq` ab2