Skip to content

Commit ef44e27

Browse files
authored
Merge pull request #29 from matthewleon/fromArrayBuffer
Buffer.fromArrayBuffer
2 parents 9298bf8 + e981fb0 commit ef44e27

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/Node/Buffer.js

+6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ exports.fromStringImpl = function (str) {
2525
};
2626
};
2727

28+
exports.fromArrayBuffer = function(ab) {
29+
return function() {
30+
return Buffer.from(ab);
31+
};
32+
};
33+
2834
exports.toArrayBuffer = function(buff) {
2935
return function() {
3036
return buff.buffer.slice(buff.byteOffset, buff.byteOffset + buff.byteLength);

src/Node/Buffer.purs

+6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module Node.Buffer
77
, create
88
, fromArray
99
, fromString
10+
, fromArrayBuffer
1011
, toArrayBuffer
1112
, read
1213
, readString
@@ -87,6 +88,11 @@ foreign import create :: forall e. Int -> Eff (buffer :: BUFFER | e) Buffer
8788
-- | Creates a new buffer from an array of octets, sized to match the array.
8889
foreign import fromArray :: forall e. Array Octet -> Eff (buffer :: BUFFER | e) Buffer
8990

91+
-- | Creates a buffer view from a JS ArrayByffer without copying data.
92+
--
93+
-- Requires Node >= v5.10.0
94+
foreign import fromArrayBuffer :: forall e. ArrayBuffer -> Eff (buffer :: BUFFER | e) Buffer
95+
9096
-- | Creates a new buffer from a string with the specified encoding, sized to
9197
-- | match the string.
9298
fromString :: forall e. String -> Encoding -> Eff (buffer :: BUFFER | e) Buffer

0 commit comments

Comments
 (0)