Add lines about additonal uses of Buffer #4257

Closed
wants to merge 2 commits into
from

Projects

None yet

4 participants

@trevnorris
Collaborator

That Buffers can be used with Typed Array Views and DataViews. Included are a couple simple examples.

@trevnorris trevnorris Add lines about additonal uses of Buffer
That Buffers can be used with Typed Array Views and DataViews. Included
are a couple simple examples.
5d81eda
@TooTallNate

Looks good, I'll merge.

The apparent global var leaks in your example kinda bugs me, mind fixing those first?

@trevnorris trevnorris Fix global var leak
Per TooTallNate's request, variables in doc have now been explicitly
declared.
dfecc7b
@trevnorris
Collaborator

@TooTallNate There ya go. Thanks for the feedback.

@Mithgol
Mithgol commented Nov 22, 2012

For a future reference, since which Node version is using Buffers with Typed Array Views and DataViews supported?

(I am considering some changes in jDataView and jParser but I am not sure how backwards-compatible that would be.)

@bnoordhuis
Member

@Mithgol 0.8. The feature was landed in one of the 0.7 dev releases.

@TooTallNate TooTallNate added a commit that closed this pull request Nov 22, 2012
@trevnorris trevnorris doc: Add lines about additonal uses of Buffer
That Buffers can be used with Typed Array Views and DataViews. Included
are a couple simple examples.

Closes #4257.
bb867c0
@TooTallNate

Thanks @trevnorris, merged in bb867c0.

@Mithgol
Mithgol commented Dec 16, 2012

@bnoordhuis I've just tried the following in Node v0.6.21:

buff = new Buffer(4);
view = new DataView(buff);
view.setInt16(0, 1);
view.setInt16(2, 2, true);
console.log(buff);

I got <Buffer 00 01 02 00>.

So the DataView() of buffers seems to be possible before 0.8 and 0.7.

I wonder how far in the past it goes and how it should be tested.

@Mithgol
Mithgol commented Dec 16, 2012

Tested in 0.6.0, got the same result.

@bnoordhuis
Member

@Mithgol The feature I mean was landed in 5b05429. It doesn't matter though, v0.6's end of life is in two weeks.

@Mithgol
Mithgol commented Dec 16, 2012

What was the Node version when the commit 5b05429 happened?

(Currently jDataView supports Node versions of 0.5.5 and above, so it does matter: I'd have to persuade that library's author to drop some support if I write some uncompatible pull request.)

@bnoordhuis
Member

What was the Node version when the commit 5b05429 happened?

git tag --contains 5b05429 :-)

(v0.7.0 is the first one.)

@Mithgol
Mithgol commented Dec 16, 2012

Wait, I understand now; the feature you meant was getting a typed array (such as Uint16Array()) out of a buffer, however, DataView() of a buffer was possible earlier.

I've just tested the same code in Node v0.5.6:

buff = new Buffer(4);
view = new DataView(buff);
view.setInt16(0, 1);
view.setInt16(2, 2, true);
console.log(buff);

Got the same output (<Buffer 00 01 02 00>).

@Mithgol
Mithgol commented Dec 16, 2012

Node v0.5.4 says DataView is not defined.

Node v0.5.5 cannot run on Windows XP.

I guess the least of the compatible versions is v0.5.6 (or v0.5.5, but I am unable to test that).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment