diff options
| author | Stefan Boberg <[email protected]> | 2022-06-10 14:52:24 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2022-06-10 14:52:24 +0200 |
| commit | c798a8878066e1078add1fbd03ee433e1133878b (patch) | |
| tree | cbfc572f0c540f6f4fbcc3eba65e196c4f203b5e /zencore/filesystem.cpp | |
| parent | http: added some more content-type aliases/suffixes (diff) | |
| download | zen-c798a8878066e1078add1fbd03ee433e1133878b.tar.xz zen-c798a8878066e1078add1fbd03ee433e1133878b.zip | |
core: added ReadStdIn
implements a simple wrapper around reading stdin until EOF
Diffstat (limited to 'zencore/filesystem.cpp')
| -rw-r--r-- | zencore/filesystem.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/zencore/filesystem.cpp b/zencore/filesystem.cpp index bd85f5a11..01997daae 100644 --- a/zencore/filesystem.cpp +++ b/zencore/filesystem.cpp @@ -6,6 +6,7 @@ #include <zencore/fmtutils.h> #include <zencore/iobuffer.h> #include <zencore/logging.h> +#include <zencore/stream.h> #include <zencore/string.h> #include <zencore/testing.h> @@ -637,6 +638,25 @@ FileContents::Flatten() } FileContents +ReadStdIn() +{ + BinaryWriter Writer; + + do + { + uint8_t ReadBuffer[1024]; + + size_t BytesRead = fread(ReadBuffer, 1, sizeof ReadBuffer, stdin); + Writer.Write(ReadBuffer, BytesRead); + } while (!feof(stdin)); + + FileContents Contents; + Contents.Data.emplace_back(IoBuffer(IoBuffer::Clone, Writer.GetData(), Writer.GetSize())); + + return Contents; +} + +FileContents ReadFile(std::filesystem::path Path) { uint64_t FileSizeBytes; |