feature(FileStream): Allow using Poco::FileStream to wrap arbitrary file handles/descriptors as C++ streams (#4424)

* Allow using Poco::FileStream to wrap arbitrary file handles/descriptors as C++ streams (#3444).

* Allow opening a file descriptor/HANDLE as C++ stream.

* FileStream: treat read from closed pipe as EOF.

* chore(Filestream): conde style (naming)

Co-Authored-By: Alex Fabijanic <alex@pocoproject.org>
Co-Authored-By: Matej Kenda <matejken@gmail.com>

* enh(FileStream): make FileIOS::open a virtual function. (#3444)

* test(FileStream): unit test for FileStream::openHandle (#3444)

* Update CONTRIBUTORS.

* test(FileStream): Win32 unit test fix.

* build(CMake): Require policy minimum version 3.15.

---------

Co-authored-by: Daniel Grunwald <grunwald@axivion.com>
Co-authored-by: Alex Fabijanic <alex@pocoproject.org>
This commit is contained in:
Matej Kenda
2024-05-08 11:53:43 +02:00
committed by GitHub
parent 1a0355f1b7
commit 065f9a0ff9
10 changed files with 131 additions and 13 deletions

View File

@@ -56,6 +56,16 @@ public:
~FileIOS();
/// Destroys the stream.
virtual void open(const std::string& path, std::ios::openmode mode);
/// Opens the file specified by path, using the given mode.
///
/// Throws a FileException (or a similar exception) if the file
/// does not exist or is not accessible for other reasons and
/// a new file cannot be created.
void openHandle(NativeHandle handle, std::ios::openmode mode);
/// Takes ownership of the handle.
void close();
/// Closes the file stream.
///
@@ -108,7 +118,7 @@ public:
~FileInputStream();
/// Destroys the stream.
void open(const std::string& path, std::ios::openmode mode = std::ios::in);
void open(const std::string& path, std::ios::openmode mode = std::ios::in) override;
/// Opens the file specified by path, using the given mode, which
/// will always include std::ios::in (even if not specified).
///
@@ -151,7 +161,7 @@ public:
~FileOutputStream();
/// Destroys the FileOutputStream.
void open(const std::string& path, std::ios::openmode mode = std::ios::out | std::ios::trunc);
void open(const std::string& path, std::ios::openmode mode = std::ios::out | std::ios::trunc) override;
/// Opens the file specified by path, using the given mode, which
/// always includes std::ios::out, even if not specified.
///
@@ -196,7 +206,7 @@ public:
~FileStream();
/// Destroys the FileOutputStream.
void open(const std::string& path, std::ios::openmode mode = std::ios::out | std::ios::in);
void open(const std::string& path, std::ios::openmode mode = std::ios::out | std::ios::in) override;
/// Opens the file specified by path, using the given mode.
///
/// Throws a FileException (or a similar exception) if the file