GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — pass Array Buffer to constructor by calvinmetcalf · Pull Request #39 · feross/buffer

Conversation

@calvinmetcalf

@calvinmetcalf calvinmetcalf commented Jul 29, 2014

Copy link
Copy Markdown
Contributor

No description provided.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@calvinmetcalf
pass Array Buffer to constructor
1270d57
feross
feross reviewed Jul 30, 2014
View reviewed changes
Comment thread test/basic.js

@feross feross Jul 30, 2014

Copy link
Copy Markdown
Owner

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't actually checking the right buffer, b2.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@calvinmetcalf calvinmetcalf Jul 30, 2014

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do'h all I checked was that it failed without this patch

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@feross

feross commented Jul 30, 2014

Copy link
Copy Markdown
Owner

Hi, thanks for the PR! I don't think this is a good idea (aside from the issues I mention inline) because it would make this module diverge from the node.js buffer API.

An ArrayBuffer is not array-like: it lacks a length property indexes can't be accessed directly via buf[0], etc. Thus, new Buffer(new Uint8Array([0, 1, 2, 3]).buffer) fails in both node.js and this module.

If you have an ArrayBuffer, just wrap it in a Uint8Array before passing it to the constructor and you'll be good.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@feross feross closed this Jul 30, 2014
@calvinmetcalf

calvinmetcalf commented Jul 30, 2014

Copy link
Copy Markdown
Contributor Author

so the impetus for this was a bug using level-js (Level/level-js#34) caused by array buffers being turned into zero length Uint8Array objects, there is some code that made me think that you intended to support array buffers, but if you don't would you accept a pull to throw or print a warning if array buffers are given to the constructor (yes strictly speaking a divergence from node, but your more likely to get a typed array in browserified contexts)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@feross

feross commented Aug 2, 2014

Copy link
Copy Markdown
Owner

The code you linked is there to support TypedArrayViews like Uint8Array, etc. which have a byteLength property as well. The set function wouldn't work with an arraybuffer. :)

If level-js claims to support ArrayBuffers here (I don't know if it does), then this is a bug in how it's using this module. It should check if it's an ArrayBuffer and wrap it in a Uint8Array.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@calvinmetcalf

calvinmetcalf commented Aug 2, 2014

Copy link
Copy Markdown
Contributor Author

right forgot the typed arrays had both

On Fri, Aug 1, 2014 at 8:16 PM, Feross Aboukhadijeh <
[email protected]> wrote:

The code https://github.com/feross/buffer/blob/master/index.js#L96 you
linked is there to support TypedArrayViews like Uint8Array, etc. which have
a byteLength property as well. The set function wouldn't work with an
arraybuffer. :)

If level-js claims to support ArrayBuffers here (I don't know if it does),
then this is a bug in how it's using this module. It should check if it's
an ArrayBuffer and wrap it in a Uint8Array.

—
Reply to this email directly or view it on GitHub
#39 (comment).

-Calvin W. Metcalf

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@feross feross mentioned this pull request Sep 11, 2014
Added support for constructing from ArrayBuffer and added test that verifies support #42
Closed
@feross feross mentioned this pull request Dec 8, 2014
feature: support initializing Buffer from an ArrayBuffer nodejs/node#106
Closed
@feross

feross commented Jun 18, 2015

Copy link
Copy Markdown
Owner

We can add support for this feature now that node.js#next has support! nodejs/node#2002

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@feross

feross commented Aug 5, 2015

Copy link
Copy Markdown
Owner

ArrayBuffer can be passed into the constructor as of buffer 3.4.0.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@calvinmetcalf

calvinmetcalf commented Aug 5, 2015

Copy link
Copy Markdown
Contributor Author

vindicated! thanks @feross

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@feross

feross commented Aug 5, 2015

Copy link
Copy Markdown
Owner

@calvinmetcalf Yeah :) I agreed it's a great idea but want to keep this module exactly in sync with node. I argued to support this - happy it finally landed!!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@calvinmetcalf @feross
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.