Optimize ByteArrayInputStream

This saves a few seconds at startup. It's also used a lot in general, so it's worth implementing it in JS.