|View source on GitHub|
File I/O wrappers without thread locking.
tf.compat.v1.gfile.FastGFile( name, mode='r' )
Note, that this is somewhat like builtin Python file I/O, but there are semantic differences to make it more efficient for some backing filesystems. For example, a write mode file will not be opened until the first write call (to minimize RPC invocations in network filesystems).
||Returns the mode in which the file was opened.|
||Returns the file name.|
Closes the file.
Should be called for the WritableFile to be flushed.
In general, if you use the context manager pattern, you don't need to call this directly.
with tf.io.gfile.GFile("/tmp/x", "w") as f:
# implicit f.close() at the end of the block
For cloud filesystems, forgetting to call
close() might result in data
loss as last write might not have been replicated.
Flushes the Writable file.
This only ensures that the data has made its way out of the process without any guarantees on whether it's written to disk. This means that the data would survive an application crash but not necessarily an OS crash.
read( n=-1 )
Returns the contents of a file as a string.
Starts reading from current position in file.
Reads the next line, keeping \n. At EOF, returns ''.
Returns all lines from the file in a list.
seek( offset=None, whence=0, position=None )
Seeks to the offset in the file. (deprecated arguments)
||The byte count relative to the whence argument.|
Valid values for whence are:
0: start of the file (default)
1: relative to the current position of the file
2: relative to the end of file.
Returns True as FileIO supports random access ops of seek()/tell()
Returns the size of the file.
Returns the current position in the file.
write( file_content )
Writes file_content to the file. Appends to the end of the file.