make sure that the buffer can .slice() before trying to slice it

This fix is necessary in environments like browsers where sometimes without warning you'll have an Int32Array instead of a string or a buffer.