Skip to content

Commit

Permalink
Merge pull request #4307 from embray/fits/issue-4307
Browse files Browse the repository at this point in the history
Saving large table FITS may lead to a truncated file
  • Loading branch information
embray committed Nov 20, 2015
1 parent 14a09f1 commit 1a0c193
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,9 @@ Bug Fixes

- ``astropy.io.fits``

- Fixed a regression that could cause writes of large FITS files to be
truncated. [#4307]

- ``astropy.io.misc``

- ``astropy.io.registry``
Expand Down
5 changes: 2 additions & 3 deletions astropy/io/fits/hdu/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
from ..file import _File
from ..header import Header, _pad_length
from ..util import (_is_int, _is_pseudo_unsigned, _unsigned_zero,
itersubclasses, decode_ascii,
_get_array_mmap, _array_to_file, first)
itersubclasses, decode_ascii, _get_array_mmap, first)
from ..verify import _Verify, _ErrList

from ....extern.six import string_types, add_metaclass
Expand Down Expand Up @@ -727,7 +726,7 @@ def _writedata_direct_copy(self, fileobj):

raw = self._get_raw_data(self._data_size, 'ubyte', self._data_offset)
if raw is not None:
_array_to_file(raw, fileobj)
fileobj.writearray(raw)
return raw.nbytes
else:
return 0
Expand Down
2 changes: 2 additions & 0 deletions astropy/io/fits/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import division

import errno
import gzip as _system_gzip
import itertools
import io
Expand Down Expand Up @@ -862,6 +863,7 @@ def _write_string(f, s):
elif isinstance(f, StringIO) and isinstance(s, np.ndarray):
# Workaround for StringIO/ndarray incompatibility
s = s.data

f.write(s)


Expand Down

0 comments on commit 1a0c193

Please sign in to comment.