MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / SkipNBytes

Method SkipNBytes

tensorflow/core/lib/io/random_inputstream.cc:70–101  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

68static constexpr int64 kMaxSkipSize = 8 * 1024 * 1024;
69
70Status RandomAccessInputStream::SkipNBytes(int64 bytes_to_skip) {
71 if (bytes_to_skip < 0) {
72 return errors::InvalidArgument("Can't skip a negative number of bytes");
73 }
74 std::unique_ptr<char[]> scratch(new char[kMaxSkipSize]);
75 // Try to read 1 bytes first, if we could complete the read then EOF is
76 // not reached yet and we could return.
77 if (bytes_to_skip > 0) {
78 StringPiece data;
79 Status s = file_->Read(pos_ + bytes_to_skip - 1, 1, &data, scratch.get());
80 if ((s.ok() || errors::IsOutOfRange(s)) && data.size() == 1) {
81 pos_ += bytes_to_skip;
82 return Status::OK();
83 }
84 }
85 // Read kDefaultSkipSize at a time till bytes_to_skip.
86 while (bytes_to_skip > 0) {
87 int64 bytes_to_read = std::min<int64>(kMaxSkipSize, bytes_to_skip);
88 StringPiece data;
89 Status s = file_->Read(pos_, bytes_to_read, &data, scratch.get());
90 if (s.ok() || errors::IsOutOfRange(s)) {
91 pos_ += data.size();
92 } else {
93 return s;
94 }
95 if (data.size() < bytes_to_read) {
96 return errors::OutOfRange("reached end of file");
97 }
98 bytes_to_skip -= bytes_to_read;
99 }
100 return Status::OK();
101}
102
103int64 RandomAccessInputStream::Tell() const { return pos_; }
104

Callers

nothing calls this directly

Calls 5

InvalidArgumentFunction · 0.85
ReadMethod · 0.45
getMethod · 0.45
okMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected