haste-compiler- Haskell To ECMAScript compiler

Safe HaskellNone



Handling of Javascript-native binary blobs.

Generics borrowed from the binary package by Lennart Kolmodin (released under BSD3)



type Put = PutM () Source

putJSString :: JSString -> Put Source

Serialize a JSString as UTF-16 (somewhat) efficiently.

skip :: Int -> Get () Source

Skip n bytes of input.

class Monad m => MonadBlob m where Source


getBlobData :: Blob -> m BlobData Source

Retrieve the raw data from a blob.

getBlobText' :: Blob -> m JSString Source

Interpret a blob as UTF-8 text, as a JSString.

class Binary a where Source

Somewhat efficient serializationdeserialization tofrom binary Blobs. The layout of the binaries producedread by getput and encode/decode may change between versions. If you need a stable binary format, you should make your own using the primitives in Haste.Binary.Get/Put.

Minimal complete definition



get :: Get a Source

put :: a -> Put Source

getBlobText :: MonadBlob m => Blob -> m String Source

Interpret a blob as UTF-8 text.

data Blob Source

A JavaScript Blob on the client, a ByteString on the server.

data BlobData Source

In a browser context, BlobData is essentially a DataView, with an accompanying offset and length for fast slicing. In a server context, it is simply a ByteString.

blobSize :: Blob -> Int Source

The size, in bytes, of the contents of the given blob.

blobDataSize :: BlobData -> Int Source

The size, in bytes, of the contents of the given blob data.

toByteString :: BlobData -> ByteString Source

Convert a BlobData to a ByteString. Only usable server-side.

fromByteString :: ByteString -> BlobData Source

Convert a ByteString to a BlobData. Only usable server-side.

toBlob :: BlobData -> Blob Source

Convert a piece of BlobData back into a Blob.

strToBlob :: JSString -> Blob Source

Create a Blob from a JSString.

encode :: Binary a => a -> Blob Source

Encode any serializable data into a Blob.

decode :: Binary a => BlobData -> Either String a Source

Decode any deserializable data from a BlobData.

decodeBlob :: (MonadBlob m, Binary a) => Blob -> m (Either String a) Source

Decode a Blob into some deserializable value, inconveniently locked up inside the CIO monad (or any other concurrent monad) due to the somewhat special way JavaScript uses to deal with binary data.