title: Empty chunks when spliting a large file
body: <p>I am trying to split a large files into 50Mb chunks and save them in another files. After running some read/write operations, some of my chunks were smaller than 50Mb (43Mb,17Mb and so on). Although, I wrote the same code in Java and It has the same problem. What is wrong? my codes are following bellow:</p>
  
  <p>By the way, What we can do to speed up this code to split into chunks faster?</p>
  
  <pre><code>try:
      f = open(self.__filename, 'rb')
  except (OSError, IOError), e:
      raise FileSplitterException, str(e)
  
  bname = (os.path.split(self.__filename))[1]
  
  fsize = os.path.getsize(self.__filename)
  
  self.__chunksize = int(float(fsize)/float(self.__numchunks))
  
  chunksz = self.__chunksize
  total_bytes = 0
  
  for x in range(self.__numchunks):
      chunkfilename = bname + '-' + str(x+1) + self.__postfix
  
      if x == self.__numchunks - 1:
          chunksz = fsize - total_bytes
  
      try:
          print 'Writing file',chunkfilename
          data = f.read(chunksz)
          total_bytes += len(data)
          chunkf = file(chunkfilename, 'wb')
          chunkf.write(data)
          chunkf.close()
      except (OSError, IOError), e:
          print e
          continue
      except EOFError, e:
          print e
          break
  </code></pre>