Skip to content

Buffer - feature request: Buffer.compare with offsets. #521

Closed
@rootslab

Description

I'm really impressed with the new iojs features, an awesome work!
Buffer.compare is a great iojs addition ( memcmp is very fast!), but, unfortunately, the current method implementation doesn't offer a way to compare 2 portions of Buffers: you are forced to slice one or both Buffers to compare desired portions of data.

Now, Buffer.compare accepts 2 buffers as arguments, instead, it could accept 4 args (+1 optional), or something like that:

function ( Buffer b1, Number start1, Buffer b2, Number start2 [, Number length ] ) {}
/*
 * For example, comparing 10 bytes:
 *  - b1 from index 0 to 9 
 *  - b2 from index 16 to 25
 */
Buffer.compare( b1, 0, b2, 16, 10 )
// or, to mantain current signature:
Buffer.compare( b1, b2, 0, 16, 10 )

@trevnorris It would be great if it was planned to add this functionality, it simplify things a lot!!

Activity

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

Metadata

Assignees

Labels

bufferIssues and PRs related to the buffer subsystem.feature requestIssues that request new features to be added to Node.js.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions