Skip to content

How to inherit from new Buffer implementation #2882

Description

@corentingurtner

Hi,
I would like to know how a class could inherit from the new Buffer implementation.

I'm trying to upgrade the node-ogg module for node v4 and nan v2.
(Here is my work so far)

I tried this classic inheritance model:

function ogg_packet (buffer) {
  if (!Buffer.isBuffer(buffer)) {
    Buffer.call(this, binding.sizeof_ogg_packet);
  } else {
    Buffer.call(this, buffer);
  }
  if (this.length != binding.sizeof_ogg_packet) {
    throw new Error('"buffer.length" = ' + this.length + ', expected ' + binding.sizeof_ogg_packet);
  }
}
inherits(ogg_packet, Buffer);

But I get this error when trying to access this.length :

Uncaught TypeError: Method Uint8Array.length called on incompatible receiver [object Object]

Thanks

Note: I also asked the question on SO:
http://stackoverflow.com/questions/32555714

Activity

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

Metadata

Metadata

Assignees

Labels

bufferIssues and PRs related to the buffer subsystem.docIssues and PRs related to Node.js documentation.questionIssues asking questions about Node.js.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions