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