def write(self, out_filename):
"""Create the TFTF file and return a success flag
Create the TFTF file (appending the default extension if omitted)
and write the TFTF buffer to it.
"""
success = True
# Prepare the output buffer
self.pack()
# Record the length of the entire TFTF blob (this will be longer
# than the header's load_length)
self.tftf_length = len(self.tftf_buf)
# Ensure the output file ends in the default TFTF file extension if
# the user hasn't specified their own extension.
if rfind(out_filename, ".") == -1:
out_filename += TFTF_FILE_EXTENSION
try:
with open(out_filename, 'wb') as wf:
# Write the TFTF header
wf.write(self.tftf_buf)
# verify the file is the correct length
try:
statinfo = os.stat(out_filename)
if statinfo.st_size != self.tftf_length:
error(out_filename, "has wrong length")
except:
error("Can't get info on", out_filename)
except:
error("Unable to write", out_filename)
success = False
else:
if success:
print("Wrote", out_filename)
else:
error("Failed to write", out_filename)
return success
评论列表
文章目录