File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed
Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -590,6 +590,21 @@ SC::Result SC::FileDescriptor::write(Span<const uint8_t> data)
590590 return write ({reinterpret_cast <const char *>(data.data ()), data.sizeInBytes ()});
591591}
592592
593+ SC::Result SC::FileDescriptor::readUntilFullOrEOF (Span<char > data, Span<char >& actuallyRead)
594+ {
595+ auto availableData = data;
596+ while (not availableData.empty ())
597+ {
598+ Span<char > readData;
599+ SC_TRY (read (availableData, readData));
600+ if (readData.empty ())
601+ break ;
602+ availableData = {availableData.data (), availableData.sizeInBytes () - readData.sizeInBytes ()};
603+ }
604+ actuallyRead = {data.data (), data.sizeInBytes () - availableData.sizeInBytes ()};
605+ return Result (true );
606+ }
607+
593608SC::Result SC::FileDescriptor::readUntilEOF (IGrowableBuffer&& adapter)
594609{
595610 char buffer[1024 ];
Original file line number Diff line number Diff line change @@ -123,6 +123,12 @@ struct SC_COMPILER_EXPORT FileDescriptor : public UniqueHandle<detail::FileDescr
123123 // / @return Valid result if read succeeded
124124 Result read (Span<char > data, Span<char >& actuallyRead);
125125
126+ // / @brief Reads bytes from current position (FileDescriptor::seek) into Span, until full or EOF is reached
127+ // / @param data Span of bytes where data should be written to
128+ // / @param actuallyRead A sub-span of data of the actually read bytes. A zero sized span means EOF.
129+ // / @return Valid result if read succeeded
130+ Result readUntilFullOrEOF (Span<char > data, Span<char >& actuallyRead);
131+
126132 // / @brief Reads bytes from current position (FileDescriptor::seek) into user supplied Span
127133 // / @param data Span of bytes where data should be written to
128134 // / @param actuallyRead A sub-span of data of the actually read bytes. A zero sized span means EOF.
You can’t perform that action at this time.
0 commit comments