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 — Added support for constructing from ArrayBuffer and added test that verifies support by robskillington · Pull Request #42 · feross/buffer

Conversation

@robskillington

@robskillington robskillington commented Sep 11, 2014

Copy link
Copy Markdown

No description provided.

Sorry, something went wrong.

Uh oh!

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

All reactions
Rob Skillington
Added support for constructing from ArrayBuffer and added test that v…
007fe02
…erifies support
@feross

feross commented Sep 11, 2014

Copy link
Copy Markdown
Owner

Thanks for the PR! I would like to accept this, but I'm very hesitant for the reasons mentioned here: #39 (comment)

All reactions

Sorry, something went wrong.

Uh oh!

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

feross
feross reviewed Sep 11, 2014
View reviewed changes
Comment thread index.js

@feross feross Sep 11, 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.

It's actually not enough to just set the length correctly. subject itself should be wrapped in a Uint8Array so the data can actually be pulled out.

Sorry, something went wrong.

Uh oh!

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

All reactions
@robskillington robskillington closed this Sep 11, 2014
@robskillington

robskillington commented Sep 11, 2014

Copy link
Copy Markdown
Author

Thanks and apologies for not seeing other issues similar to this =]

All reactions

Sorry, something went wrong.

Uh oh!

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

@feross

feross commented Sep 11, 2014

Copy link
Copy Markdown
Owner

No problem. :) I'd open an issue with websocket-stream if you still think there's a bug here, though I expect you could just do new Buffer(new Uint8Array(arraybuffer)) in your own code.

All reactions

Sorry, something went wrong.

Uh oh!

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

@robskillington

robskillington commented Sep 11, 2014

Copy link
Copy Markdown
Author

So specifically mows which is an MQTT over WebSocket adapter is explicitly providing Uint8Array as the buffer type that websocket-stream should use: https://github.com/mcollina/mows/blob/master/buildWebsocketBrowser.js

This means it will new Uint8Array(incomingDataAsArrayBufferInstance) and then all the code therein breaks as websocket-stream is expecting a Nodejs Buffer API compatible buffer. Herein I updated to use just straight up Buffer using your fantastic work =] However I can't just provide type Buffer because this cannot build a Buffer from an ArrayBuffer. Hence here is my solution which I should ship back to mows now likely:

opts.type = BufferPatched;
//...
function BufferPatched(subject) {
    if (subject instanceof ArrayBuffer) {
        subject = new Uint8Array(subject);
    }
    return Buffer.apply(this, arguments);
}

util.inherits(BufferPatched, Buffer);
All reactions

Sorry, something went wrong.

Uh oh!

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

@feross

feross commented Sep 11, 2014

Copy link
Copy Markdown
Owner

This sounds like reasonable solution to me :)

All reactions

Sorry, something went wrong.

Uh oh!

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

@robskillington

robskillington commented Sep 11, 2014

Copy link
Copy Markdown
Author

Just thinking: would adding to the constructor of Buffer in this library add ArrayBuffer support for everyone?

    if (typeof ArrayBuffer === 'function' && subject instanceof ArrayBuffer) {
        subject = new Uint8Array(subject);
    }
All reactions

Sorry, something went wrong.

Uh oh!

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

@feross

feross commented Sep 11, 2014

Copy link
Copy Markdown
Owner

It would, and it's tempting to add it. But I'm worried that people would write code that depends on this behavior when it won't work in node.js. Maybe I should just send a PR to node core since this is an annoying API issue that keeps coming up.

All reactions

Sorry, something went wrong.

Uh oh!

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

@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.

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

@robskillington @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.