Skip to content

Commit

Permalink
Merge pull request #27 from matthewleon/toArrayBuffer
Browse files Browse the repository at this point in the history
toArrayBuffer. resolves #22
  • Loading branch information
paf31 authored Nov 19, 2017
2 parents 6b7a3f4 + 8852bd5 commit 9298bf8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
},
"dependencies": {
"purescript-eff": "^3.0.0",
"purescript-maybe": "^3.0.0"
"purescript-maybe": "^3.0.0",
"purescript-arraybuffer-types": "^2.0.0"
},
"devDependencies": {
"purescript-assert": "^3.0.0",
Expand Down
6 changes: 6 additions & 0 deletions src/Node/Buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ exports.fromStringImpl = function (str) {
};
};

exports.toArrayBuffer = function(buff) {
return function() {
return buff.buffer.slice(buff.byteOffset, buff.byteOffset + buff.byteLength);
};
};

exports.readImpl = function (ty) {
return function (offset) {
return function (buf) {
Expand Down
5 changes: 5 additions & 0 deletions src/Node/Buffer.purs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module Node.Buffer
, create
, fromArray
, fromString
, toArrayBuffer
, read
, readString
, toString
Expand All @@ -23,7 +24,9 @@ module Node.Buffer
) where

import Prelude

import Control.Monad.Eff (Eff, kind Effect)
import Data.ArrayBuffer.Types (ArrayBuffer)
import Data.Maybe (Maybe(..))
import Node.Encoding (Encoding, encodingToNode)

Expand Down Expand Up @@ -91,6 +94,8 @@ fromString str = fromStringImpl str <<< encodingToNode

foreign import fromStringImpl :: forall e. String -> String -> Eff (buffer :: BUFFER | e) Buffer

foreign import toArrayBuffer :: forall e. Buffer -> Eff (buffer :: BUFFER | e) ArrayBuffer

-- | Reads a numeric value from a buffer at the specified offset.
read :: forall e. BufferValueType -> Offset -> Buffer -> Eff (buffer :: BUFFER | e) Int
read = readImpl <<< show
Expand Down

0 comments on commit 9298bf8

Please sign in to comment.