• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2016 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 #ifndef TENSORFLOW_CORE_LIB_IO_INPUTSTREAM_INTERFACE_H_
17 #define TENSORFLOW_CORE_LIB_IO_INPUTSTREAM_INTERFACE_H_
18 
19 #include <string>
20 
21 #include "tensorflow/core/lib/core/errors.h"
22 #include "tensorflow/core/lib/core/status.h"
23 #include "tensorflow/core/platform/cord.h"
24 #include "tensorflow/core/platform/types.h"
25 
26 namespace tensorflow {
27 namespace io {
28 
29 // An interface that defines input streaming operations.
30 class InputStreamInterface {
31  public:
InputStreamInterface()32   InputStreamInterface() {}
~InputStreamInterface()33   virtual ~InputStreamInterface() {}
34 
35   // Reads the next bytes_to_read from the file. Typical return codes:
36   //  * OK - in case of success.
37   //  * OUT_OF_RANGE - not enough bytes remaining before end of file.
38   virtual Status ReadNBytes(int64 bytes_to_read, tstring* result) = 0;
39 
40 #if defined(TF_CORD_SUPPORT)
41   // Reads the next bytes_to_read from the file. Typical return codes:
42   //  * OK - in case of success.
43   //  * OUT_OF_RANGE - not enough bytes remaining before end of file.
ReadNBytes(int64 bytes_to_read,absl::Cord * cord)44   virtual Status ReadNBytes(int64 bytes_to_read, absl::Cord* cord) {
45     return errors::Unimplemented(
46         "ReadNBytes(int64, absl::Cord*) is not implemented.");
47   }
48 #endif
49 
50   // Skips bytes_to_skip before next ReadNBytes. bytes_to_skip should be >= 0.
51   // Typical return codes:
52   //  * OK - in case of success.
53   //  * OUT_OF_RANGE - not enough bytes remaining before end of file.
54   virtual Status SkipNBytes(int64 bytes_to_skip);
55 
56   // Return the offset of the current byte relative to the beginning of the
57   // file.
58   // If we Skip / Read beyond the end of the file, this should return the length
59   // of the file.
60   // If there are any errors, this must return -1.
61   virtual int64 Tell() const = 0;
62 
63   // Resets the stream to the beginning.
64   virtual Status Reset() = 0;
65 };
66 
67 }  // namespace io
68 }  // namespace tensorflow
69 
70 #endif  // TENSORFLOW_CORE_LIB_IO_INPUTSTREAM_INTERFACE_H_
71