just convert your 2D to a 1D, read along a row, then read along the next row etc and save them in one long row! then you could save how long the original row lengths were and read them out with the inverse algorithm, or append a set number of bytes to the end of your array that you can get the original row length from.