I actually did try writing something at the extended position, although I removed it before posting the above. Even with a write, it still does not do as expected. In fact, the results are even stranger:
#lang racket
(define (say . args) (displayln (apply ~a args)))
(define the-path "./test-file")
(when (file-exists? the-path) (delete-file the-path))
(say "before open, file exists?: " (file-exists? the-path))
(let ([the-port (open-output-file the-path #:mode 'binary #:exists 'append)])
(say "after open, file exists?: " (file-exists? the-path))
(say "before repos, file size, position: " (file-size the-path) ", "
(file-position the-port))
(file-position the-port 1000); should extend the file and fill the intervening space with 0
(say "before flush, file size, position: " (file-size the-path) ", "
(file-position the-port))
(flush-output the-port) ; ensure that the filling 0s have been written, just to be sure
(say "before write, file size, position: " (file-size the-path) ", "
(file-position the-port))
(write "foo" the-port)
(say "before 2nd flush, file size, position: "
(file-size the-path) ", " (file-position the-port))
(flush-output the-port)
(say "finally, file size, position: " (file-size the-path) ", " (file-position the-port))
)
Ouptut:
before open, file exists?: #f
after open, file exists?: #t
before repos, file size, position: 0, 0
before flush, file size, position: 0, 1000
before write, file size, position: 0, 1000
before 2nd flush, file size, position: 0, 1005
finally, file size, position: 5, 5
Personally, i find this even weirder. I wrote 3 characters, so why is the file size 5? (Which it is, on disk.)