nipy/nibabel — pull request #213 by matthew-brett (2013-11-20 17:53:30+00:00)
Title: WIP: reset file offset to zero creating image

This is a minor API break, and I'd really like a review.

Before this PR, you would read an image, and the header would contain the data
offset value. For single file images, the data offset would typically point to
the end of the header, but it's also possible to have data at the beginning of
a file that is not part of the image. So the 'offset' field would be non-zero -
say 400.

When using this header to write out an image, or initialize a new image, the
offset field gets maintained - so the newly written image, and any image based
on the same header, also have an offset of e.g. 400.

This doesn't make much sense usually - because - if we save images to
filenames, we open 'wb' and write the whole file, so even if an existing output
image file had something interesting from 0-400, it would get overwritten with
zeros in the default write process.

The only time this doesn't happen is if you open the file object in append mode
and pass that into the image creation - but this is obviously rather rare.

This PR sets the offset to 0 in the header each time we create a new image or
load an image. The 0 signifies 'modify at will' to the code. The writing code
then sets the offset to whatever value is necessary.

If you really want to set the offset to a specific value, you can do that by
hand with:

img.header.set_data_offset(400)

in which case the writing code uses that offset, or raises an error if the
offset is too low.

This PR addresses : https://github.com/nipy/nibabel/issues/105

@moloney - could you take a look and see if this gives what you need?