MCPcopy Create free account
hub / github.com/chipsalliance/Surelog / readContent

Method readContent

src/Common/FileSystem.cpp:133–160  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

131}
132
133bool FileSystem::readContent(PathId fileId, std::string &content) {
134 if (!fileId) return false;
135
136 bool result = false;
137 std::streamsize length = 0;
138 if (filesize(fileId, &length)) {
139 std::istream &strm = openForRead(fileId);
140 if (strm.good()) {
141 content.resize(length);
142
143 std::streamsize offset = 0;
144 while (!strm.eof() && (offset < length)) {
145 strm.read(content.data() + offset, length - offset);
146 offset += strm.gcount();
147 }
148 // Can't compare the offset to length for identifying success
149 // Based on platform, filesize returns number of bytes when
150 // the file is loaded in binary mode. But when reading the file
151 // as text (as here is the case), the underlying stream automatically
152 // strips '\r' (at least in the case of Windows) and thus the number
153 // of actual bytes loaded are less than the number of bytes on disk.
154 if (offset != length) content.resize(offset);
155 result = (offset == length) || strm.eof();
156 }
157 close(strm);
158 }
159 return result;
160}
161
162bool FileSystem::writeContent(PathId fileId, std::string_view content,
163 bool onlyIfModified) {

Callers 2

processArgs_Method · 0.80
TESTFunction · 0.80

Calls

no outgoing calls

Tested by 1

TESTFunction · 0.64