1# Copyright 2015 The TensorFlow Authors. All Rights Reserved. 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14# ============================================================================== 15 16"""Import router for file_io.""" 17from __future__ import absolute_import 18from __future__ import division 19from __future__ import print_function 20 21# pylint: disable=unused-import 22from tensorflow.python.lib.io.file_io import copy as Copy 23from tensorflow.python.lib.io.file_io import create_dir as MkDir 24from tensorflow.python.lib.io.file_io import delete_file as Remove 25from tensorflow.python.lib.io.file_io import delete_recursively as DeleteRecursively 26from tensorflow.python.lib.io.file_io import file_exists as Exists 27from tensorflow.python.lib.io.file_io import FileIO as _FileIO 28from tensorflow.python.lib.io.file_io import get_matching_files as Glob 29from tensorflow.python.lib.io.file_io import is_directory as IsDirectory 30from tensorflow.python.lib.io.file_io import list_directory as ListDirectory 31from tensorflow.python.lib.io.file_io import recursive_create_dir as MakeDirs 32from tensorflow.python.lib.io.file_io import rename as Rename 33from tensorflow.python.lib.io.file_io import stat as Stat 34from tensorflow.python.lib.io.file_io import walk as Walk 35# pylint: enable=unused-import 36from tensorflow.python.util.deprecation import deprecated 37from tensorflow.python.util.tf_export import tf_export 38 39 40@tf_export('io.gfile.GFile', v1=['gfile.GFile', 'gfile.Open', 'io.gfile.GFile']) 41class GFile(_FileIO): 42 """File I/O wrappers without thread locking. 43 44 The main roles of the `tf.io.gfile` module are: 45 46 1. To provide an API that is close to Python's file I/O objects, and 47 2. To provide an implementation based on TensorFlow's C++ FileSystem API. 48 49 The C++ FileSystem API supports multiple file system implementations, 50 including local files, Google Cloud Storage (using a `gs://` prefix, and 51 HDFS (using an `hdfs://` prefix). TensorFlow exports these as `tf.io.gfile`, 52 so that you can use these implementations for saving and loading checkpoints, 53 writing to TensorBoard logs, and accessing training data (among other uses). 54 However, if all your files are local, you can use the regular Python file 55 API without any problem. 56 57 *Note*: though similar to Python's I/O implementation, there are semantic 58 differences to make `tf.io.gfile` more efficient for backing filesystems. For 59 example, a write mode file will not be opened until the first write call, to 60 minimize RPC invocations in network filesystems. 61 """ 62 63 def __init__(self, name, mode='r'): 64 super(GFile, self).__init__(name=name, mode=mode) 65 66 67@tf_export(v1=['gfile.FastGFile']) 68class FastGFile(_FileIO): 69 """File I/O wrappers without thread locking. 70 71 Note, that this is somewhat like builtin Python file I/O, but 72 there are semantic differences to make it more efficient for 73 some backing filesystems. For example, a write mode file will 74 not be opened until the first write call (to minimize RPC 75 invocations in network filesystems). 76 """ 77 78 @deprecated(None, 'Use tf.gfile.GFile.') 79 def __init__(self, name, mode='r'): 80 super(FastGFile, self).__init__(name=name, mode=mode) 81 82 83# Does not alias to Open so that we use our version of GFile to strip 84# 'b' mode. 85Open = GFile 86