Silly mistake, the code here was byteswapping in-place which corrupts the data structure that is used later to write the correct file.
Silly mistake, the code here was byteswapping in-place which corrupts the data structure that is used later to write the correct file.