Skip to content

Instantly share code, notes, and snippets.

@ThisIsMissEm
Created October 11, 2010 17:55
Show Gist options
  • Save ThisIsMissEm/620945 to your computer and use it in GitHub Desktop.
Save ThisIsMissEm/620945 to your computer and use it in GitHub Desktop.
var common = require("../common");
var assert = common.assert;
var b = require("buffer");
var SlowBuffer = b.SlowBuffer;
var c = new Buffer(50);
for(var i=0;i<c.length; ++i){
c[i] = 0x00;
assert.equal(c[i], 0x00);
}
c.write("\xFF", 25, "binary")
var s = new SlowBuffer(50);
for(var i=0;i<s.length; ++i){
s[i] = 0x00;
assert.equal(s[i], 0x00);
}
s.write("\xFF", 25, "binary")
assert.equal(c.indexOf(0xff), 25);
assert.equal(c.indexOf(0xff, 25), 0);
assert.equal(c.indexOf(0xff, 25, 25), 0);
assert.equal(c.indexOf(0xff, 26), -1);
assert.throws(c.indexOf(0xff, 26, 25));
assert.equal(s.indexOf(0xff), 25)
assert.equal(s.indexOf(0xff, 25), 0)
assert.equal(s.indexOf(0xff, 25, 25), 0)
assert.equal(s.indexOf(0xff, 26), -1)
assert.throws(s.indexOf(0xff, 26, 25))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment