diff --git a/bower.json b/bower.json index 60c7536..53756c3 100644 --- a/bower.json +++ b/bower.json @@ -14,11 +14,13 @@ }, "dependencies": { "purescript-eff": "^3.0.0", + "purescript-generics": "^4.0.0", "purescript-maybe": "^3.0.0" }, "devDependencies": { "purescript-assert": "^3.0.0", "purescript-console": "^3.0.0", + "purescript-psci-support": "^3.0.0", "purescript-foldable-traversable": "^3.0.0" } } diff --git a/src/Node/Buffer.purs b/src/Node/Buffer.purs index 0a5f7dd..c5b4729 100644 --- a/src/Node/Buffer.purs +++ b/src/Node/Buffer.purs @@ -24,7 +24,11 @@ module Node.Buffer import Prelude import Control.Monad.Eff (Eff, kind Effect) +import Control.Monad.Eff.Unsafe (unsafePerformEff) import Data.Maybe (Maybe(..)) +import Data.Generic (class Generic, toSpine, fromSpine, GenericSignature (SigProd), GenericSpine (SProd)) +import Data.Array as Array +import Type.Proxy (Proxy (..)) import Node.Encoding (Encoding, encodingToNode) -- | Type synonym indicating the value should be an octet (0-255). If the value @@ -37,6 +41,19 @@ type Offset = Int -- | An instance of Node's Buffer class. foreign import data Buffer :: Type +instance genericBuffer :: Generic Buffer where + toSpine x = SProd "Node.Buffer.Buffer" [\_ -> toSpine $ unsafePerformEff $ toArray x] + toSignature Proxy = SigProd "Node.Buffer.Buffer" [{sigConstructor: "Node.Buffer.Buffer", sigValues: []}] + fromSpine s = case s of + SProd d xs + | d == "Node.Buffer.Buffer" -> case Array.head xs of + Just y -> case fromSpine (y unit) of + Just xs' -> Just $ unsafePerformEff $ fromArray xs' + _ -> Nothing + _ -> Nothing + | otherwise -> Nothing + _ -> Nothing + instance showBuffer :: Show Buffer where show = showImpl