Skip to content

Buffer.fromArrayBuffer #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 11, 2017
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
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