Skip to content

Commit

Permalink
Merge pull request #29 from matthewleon/fromArrayBuffer
Browse files Browse the repository at this point in the history
Buffer.fromArrayBuffer
  • Loading branch information
paf31 authored Dec 11, 2017
2 parents 9298bf8 + e981fb0 commit ef44e27
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
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.fromArrayBuffer = function(ab) {
return function() {
return Buffer.from(ab);
};
};

exports.toArrayBuffer = function(buff) {
return function() {
return buff.buffer.slice(buff.byteOffset, buff.byteOffset + buff.byteLength);
Expand Down
6 changes: 6 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
, fromArrayBuffer
, toArrayBuffer
, read
, readString
Expand Down Expand Up @@ -87,6 +88,11 @@ foreign import create :: forall e. Int -> Eff (buffer :: BUFFER | e) Buffer
-- | Creates a new buffer from an array of octets, sized to match the array.
foreign import fromArray :: forall e. Array Octet -> Eff (buffer :: BUFFER | e) Buffer

-- | Creates a buffer view from a JS ArrayByffer without copying data.
--
-- Requires Node >= v5.10.0
foreign import fromArrayBuffer :: forall e. ArrayBuffer -> Eff (buffer :: BUFFER | e) Buffer

-- | Creates a new buffer from a string with the specified encoding, sized to
-- | match the string.
fromString :: forall e. String -> Encoding -> Eff (buffer :: BUFFER | e) Buffer
Expand Down

0 comments on commit ef44e27

Please sign in to comment.