1 | #include "duckdb/common/pipe_file_system.hpp" |
2 | #include "duckdb/common/exception.hpp" |
3 | #include "duckdb/common/file_system.hpp" |
4 | #include "duckdb/common/helper.hpp" |
5 | |
6 | namespace duckdb { |
7 | class PipeFile : public FileHandle { |
8 | public: |
9 | PipeFile(unique_ptr<FileHandle> child_handle_p, const string &path) |
10 | : FileHandle(pipe_fs, path), child_handle(std::move(child_handle_p)) { |
11 | } |
12 | |
13 | PipeFileSystem pipe_fs; |
14 | unique_ptr<FileHandle> child_handle; |
15 | |
16 | public: |
17 | int64_t ReadChunk(void *buffer, int64_t nr_bytes); |
18 | int64_t WriteChunk(void *buffer, int64_t nr_bytes); |
19 | |
20 | void Close() override { |
21 | } |
22 | }; |
23 | |
24 | int64_t PipeFile::ReadChunk(void *buffer, int64_t nr_bytes) { |
25 | return child_handle->Read(buffer, nr_bytes); |
26 | } |
27 | int64_t PipeFile::WriteChunk(void *buffer, int64_t nr_bytes) { |
28 | return child_handle->Write(buffer, nr_bytes); |
29 | } |
30 | |
31 | void PipeFileSystem::Reset(FileHandle &handle) { |
32 | throw InternalException("Cannot reset pipe file system" ); |
33 | } |
34 | |
35 | int64_t PipeFileSystem::Read(FileHandle &handle, void *buffer, int64_t nr_bytes) { |
36 | auto &pipe = handle.Cast<PipeFile>(); |
37 | return pipe.ReadChunk(buffer, nr_bytes); |
38 | } |
39 | |
40 | int64_t PipeFileSystem::Write(FileHandle &handle, void *buffer, int64_t nr_bytes) { |
41 | auto &pipe = handle.Cast<PipeFile>(); |
42 | return pipe.WriteChunk(buffer, nr_bytes); |
43 | } |
44 | |
45 | int64_t PipeFileSystem::GetFileSize(FileHandle &handle) { |
46 | return 0; |
47 | } |
48 | |
49 | void PipeFileSystem::FileSync(FileHandle &handle) { |
50 | } |
51 | |
52 | unique_ptr<FileHandle> PipeFileSystem::OpenPipe(unique_ptr<FileHandle> handle) { |
53 | auto path = handle->path; |
54 | return make_uniq<PipeFile>(args: std::move(handle), args&: path); |
55 | } |
56 | |
57 | } // namespace duckdb |
58 | |