Visitar URL original
buffer: add buf.mask for ws by chrisdickinson · Pull Request #1202 · nodejs/node · GitHub
Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
document and add rough tests for return value
  • Loading branch information
chrisdickinson committed Mar 19, 2015
commit 7ef29aca42e02b7e2ed887d66daf88fc60e5832c
2 changes: 2 additions & 0 deletions doc/api/buffer.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,8 @@ corresponding parameters to

The target region of memory may overlap the source region of memory.

Returns the number of bytes masked and written into `targetBuffer`.

### buffer.values()

Creates iterator for buffer values (bytes). This function is called automatically
Expand Down
13 changes: 12 additions & 1 deletion test/parallel/test-buffer-mask.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ var tests = [
testBasic,
testBounds,
testOverflow,
testNonAligned
testNonAligned,
testReturnValue
]

tests.forEach(Function.prototype.call.bind(Function.prototype.call))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Clever... but a hell of a lot longer than tests.forEach(function(f) { f(); }) :-)

Minor style nit: missing semicolon.

Expand Down Expand Up @@ -79,3 +80,13 @@ function testNonAligned() {
assert.equal(output[i], refoutput[i]);
}
}

function testReturnValue() {
var input = new Buffer(16);
var output = new Buffer(16);
assert.equal(input.mask(0, output), 16)
assert.equal(input.mask(0, output, 4), 12)
assert.equal(input.mask(0, output, 4, 6), 10)
assert.equal(input.mask(0, output, 4, 6, 4), 0)
assert.equal(input.mask(0, output, 4, 6, 8), 2)
}