But that's a common misconception and not how Ctrl-D works on Unix.
Ctrl-D is part of the terminal discipline and causes an immediate stop
of the current read(2) syscall. If nothing is in the input buffer,
this causes a zero-length read which is detected as end of file.
I once read a Patricia Cornwell novel in which the plot hinged around some crooked person typing
cat > ttya
Somebody is coming
meaning to send a message to /dev/ttya, but instead, creating a file named "ttya".
(I almost surely have the details wrong, but I'm too lazy to go searching for the real quote, which isn't relevant here.)
Cornwell said the ttya file was of size 18, so, being an obsessive nit-picker, I sent her a letter saying that it could have been 18 bytes long,
but that would imply that the sender terminated the message with CTRL-D rather than a newline and then terminating the command,
the latter of which seemed much more plausible for a novice user. Rather than ignoring my letter, or telling me where to shove my letter,
she sent me a gracious thank you note, and an FBI hat, which I still own.