Fix writeBytes length

Credit to wilsynet
synchronizing with parent repository