def pack_header(hdr, structured=0):
"""
Returns the header in the form of a string.
Pack the given BLUE header dictionary to its binary format for
storage on disk. All keywords, main and extended, are packed
and updated in the hdr dict that is passed in.
If you intend on writing this header out to disk, do not forget to
write out the extended header as well. It should be written at
512*hdr['ext_start'] bytes offset from the beginning of the file
and the extended header itself should be padded out to a multiple
of 512 bytes.
If there is an extended header present, setting the optional
<structured> argument to true (default is false) will cause any
Python dictionaries, lists, and tuples to be packed with their
structures intact. See the doc string for pack_keywords() for
more details.
"""
# Leave the user's copy alone
hdr = hdr.copy()
# Pack the main header keywords
pack_main_header_keywords(hdr)
# We have to pack the adjunct part explicitly because it is a union
endian = _rep_tran[hdr['head_rep']]
# Recalculate class from current type (user may have changed)
file_class = int(hdr['type'] / 1000)
hdr['adjunct'] = _pack_blue_struct(hdr, _bluestructs['T%dADJUNCT' %
file_class], endian)
# Pack the extended header if present
if hdr.has_key('ext_header'):
pack_ext_header(hdr, structured=structured)
return _pack_blue_struct(hdr, _bluestructs['HEADER'], endian)
评论列表
文章目录