Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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