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 #include "tensorflow/core/platform/env.h"
17 #include "tensorflow/core/platform/null_file_system.h"
18 
19 namespace tensorflow {
20 
21 class TestRandomAccessFile : public RandomAccessFile {
22   // The file contents is 10 bytes of all A's
Read(uint64 offset,size_t n,StringPiece * result,char * scratch) const23   Status Read(uint64 offset, size_t n, StringPiece* result,
24               char* scratch) const override {
25     Status s;
26     for (int i = 0; i < n; ++i) {
27       if (offset + i >= 10) {
28         n = i;
29         s = errors::OutOfRange("EOF");
30         break;
31       }
32       scratch[i] = 'A';
33     }
34     *result = StringPiece(scratch, n);
35     return s;
36   }
37 };
38 
39 class TestFileSystem : public NullFileSystem {
40  public:
NewRandomAccessFile(const string & fname,TransactionToken * token,std::unique_ptr<RandomAccessFile> * result)41   Status NewRandomAccessFile(
42       const string& fname, TransactionToken* token,
43       std::unique_ptr<RandomAccessFile>* result) override {
44     result->reset(new TestRandomAccessFile);
45     return Status::OK();
46   }
47   // Always return size of 10
GetFileSize(const string & fname,TransactionToken * token,uint64 * file_size)48   Status GetFileSize(const string& fname, TransactionToken* token,
49                      uint64* file_size) override {
50     *file_size = 10;
51     return Status::OK();
52   }
53 };
54 
55 REGISTER_FILE_SYSTEM("test", TestFileSystem);
56 
57 }  // namespace tensorflow
58