When writing binary files in Python I seem to be missing some bytes. I've tried this with the "write" function and with the "array.tofile" function. Here is some example code:
import zlib, sys, os, array
from struct import unpack
from array import array
inputFile = 'strings.exe'
print "Reading data from: ", inputFile
print 'Input File Size:', os.path.getsize(inputFile)
f = open(inputFile, 'rb')
#compressedDocument =
document = f.read()
documentArray = array('c', document)
print 'Document Size:', len(documentArray)
copyFile = open( 'Copy of ' + inputFile, 'wb')
documentArray.tofile(copyFile)
#copyFile.write(document)
copyFile.close
print 'Output File Size:', os.path.getsize('Copy of ' + inputFile)
print 'Missing Bytes:', os.path.getsize(inputFile) - os.path.getsize('Copy of ' + inputFile)
f.close()
Gives the following output:
Reading data from: strings.exe
Input File Size: 136592
Document Size: 136592
Output File Size: 135168
Missing Bytes: 1424
I don't understand why those bytes aren't being written. I've tried this on multiple files with a varying number of missing bytes.