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

Function ReadFileToString

tensorflow/core/platform/env.cc:394–421  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

392EnvWrapper::~EnvWrapper() {}
393
394Status ReadFileToString(Env* env, const string& fname, string* data) {
395 uint64 file_size;
396 Status s = env->GetFileSize(fname, &file_size);
397 if (!s.ok()) {
398 return s;
399 }
400 std::unique_ptr<RandomAccessFile> file;
401 s = env->NewRandomAccessFile(fname, &file);
402 if (!s.ok()) {
403 return s;
404 }
405 gtl::STLStringResizeUninitialized(data, file_size);
406 char* p = gtl::string_as_array(data);
407 StringPiece result;
408 s = file->Read(0, file_size, &result, p);
409 if (!s.ok()) {
410 data->clear();
411 } else if (result.size() != file_size) {
412 s = errors::Aborted("File ", fname, " changed while reading: ", file_size,
413 " vs. ", result.size());
414 data->clear();
415 } else if (result.data() == p) {
416 // Data is already in the correct location
417 } else {
418 memmove(p, result.data(), result.size());
419 }
420 return s;
421}
422
423Status WriteStringToFile(Env* env, const string& fname,
424 const StringPiece& data) {

Callers 15

ExtractMinMaxRecordsFunction · 0.85
RunFunction · 0.85
RunFunction · 0.85
CopyExportFunction · 0.85
ReadPcmFileFunction · 0.85
ReadInfoFileFunction · 0.85
ReadVideoFileFunction · 0.85
TESTFunction · 0.85
CompilePtxFunction · 0.85
TESTFunction · 0.85

Calls 9

string_as_arrayFunction · 0.85
GetFileSizeMethod · 0.45
okMethod · 0.45
NewRandomAccessFileMethod · 0.45
ReadMethod · 0.45
clearMethod · 0.45
sizeMethod · 0.45
dataMethod · 0.45

Tested by 15

CopyExportFunction · 0.68
TESTFunction · 0.68
TESTFunction · 0.68
CompareWithGoldenFileFunction · 0.68
TESTFunction · 0.68
GetVerifiedHloModuleMethod · 0.68
GenerateTsOpFileTextFunction · 0.68
ReadFileToStringOrDieFunction · 0.68
TestToFromProtoMethod · 0.68