make safe for binary data

This fixes a bug where binary data would be corrupted.