module JavaScript.TypedArray.ArrayBuffer
( ArrayBuffer
, MutableArrayBuffer
, freeze, unsafeFreeze
, thaw, unsafeThaw
, byteLength
) where
import JavaScript.TypedArray.ArrayBuffer.Internal
import GHC.Exts
import GHC.Types
create :: Int -> IO MutableArrayBuffer
create n = fmap SomeArrayBuffer (IO (js_create n))
{-# INLINE create #-}
freeze :: MutableArrayBuffer -> IO ArrayBuffer
freeze (SomeArrayBuffer b) = fmap SomeArrayBuffer (IO (js_slice1 0 b))
{-# INLINE freeze #-}
unsafeFreeze :: MutableArrayBuffer -> IO ArrayBuffer
unsafeFreeze (SomeArrayBuffer b) = pure (SomeArrayBuffer b)
{-# INLINE unsafeFreeze #-}
thaw :: ArrayBuffer -> IO MutableArrayBuffer
thaw (SomeArrayBuffer b) = fmap SomeArrayBuffer (IO (js_slice1 0 b))
{-# INLINE thaw #-}
unsafeThaw :: ArrayBuffer -> IO MutableArrayBuffer
unsafeThaw (SomeArrayBuffer b) = pure (SomeArrayBuffer b)
{-# INLINE unsafeThaw #-}
slice :: Int -> Maybe Int -> SomeArrayBuffer any -> SomeArrayBuffer any
slice begin (Just end) b = js_slice_imm begin end b
slice begin _ b = js_slice1_imm begin b
{-# INLINE slice #-}
byteLength :: SomeArrayBuffer any -> Int
byteLength b = js_byteLength b
{-# INLINE byteLength #-}