var length = 256;
var buf = new Buffer(length);
for (var i = 0; i < length; ++i) {
buf[i] = i;
}
var string = buf.toString();
for(var i = 0; i < string.length; i++) {
console.log("i",i, string[i], string.charCodeAt(i));
}
results in the following output:
i 123 { 123
i 124 | 124
i 125 } 125
i 126 ~ 126
i 127 ⌂ 127
i 128 ? 65533
i 129 ? 65533
i 130 ? 65533
i 131 ? 65533
i 132 ? 65533
I cannot quite get my head around the fact, that the charCodeAt() suddenly changes from 127 to 65533. I also took a look at the source code of buffer.js and node_buffer.cc, but could not find code that explains this behaviour. Is this behavior intended? If so, could someone explain why?
results in the following output:
I cannot quite get my head around the fact, that the
charCodeAt()suddenly changes from 127 to 65533. I also took a look at the source code ofbuffer.jsandnode_buffer.cc, but could not find code that explains this behaviour. Is this behavior intended? If so, could someone explain why?