code: def resize_file(fobj, diff, BUFFER_SIZE=2 ** 16):
      
  
      fobj.seek(0, 2)
      filesize = fobj.tell()
  
      if diff < 0:
          if filesize + diff < 0:
              raise ValueError
          # truncate flushes internally
          fobj.truncate(filesize + diff)
      elif diff > 0:
          try:
              while diff:
                  addsize = min(BUFFER_SIZE, diff)
                  fobj.write(b"\x00" * addsize)
                  diff -= addsize
              fobj.flush()
          except IOError as e:
              if e.errno == errno.ENOSPC:
                  # To reduce the chance of corrupt files in case of missing
                  # space try to revert the file expansion back. Of course
                  # in reality every in-file-write can also fail due to COW etc.
                  # Note: IOError gets also raised in flush() due to buffering
                  fobj.truncate(filesize)
              raise
docs: Resize a file by `diff`.
  
      New space will be filled with zeros.
  
      Args:
          fobj (fileobj)
          diff (int): amount of size to change
      Raises:
          IOError