Tested: * Manually using both path and file descriptor. PiperOrigin-RevId: 475860978 (cherry picked from commit 9ec4e134)