]>
Commit | Line | Data |
---|---|---|
1d09f67e TL |
1 | // Licensed to the Apache Software Foundation (ASF) under one |
2 | // or more contributor license agreements. See the NOTICE file | |
3 | // distributed with this work for additional information | |
4 | // regarding copyright ownership. The ASF licenses this file | |
5 | // to you under the Apache License, Version 2.0 (the | |
6 | // "License"); you may not use this file except in compliance | |
7 | // with the License. You may obtain a copy of the License at | |
8 | // | |
9 | // http://www.apache.org/licenses/LICENSE-2.0 | |
10 | // | |
11 | // Unless required by applicable law or agreed to in writing, | |
12 | // software distributed under the License is distributed on an | |
13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
14 | // KIND, either express or implied. See the License for the | |
15 | // specific language governing permissions and limitations | |
16 | // under the License. | |
17 | ||
18 | // Compressed stream implementations | |
19 | ||
20 | #pragma once | |
21 | ||
22 | #include <memory> | |
23 | #include <string> | |
24 | ||
25 | #include "arrow/io/concurrency.h" | |
26 | #include "arrow/io/interfaces.h" | |
27 | #include "arrow/util/visibility.h" | |
28 | ||
29 | namespace arrow { | |
30 | ||
31 | class MemoryPool; | |
32 | class Status; | |
33 | ||
34 | namespace util { | |
35 | ||
36 | class Codec; | |
37 | ||
38 | } // namespace util | |
39 | ||
40 | namespace io { | |
41 | ||
42 | class ARROW_EXPORT CompressedOutputStream : public OutputStream { | |
43 | public: | |
44 | ~CompressedOutputStream() override; | |
45 | ||
46 | /// \brief Create a compressed output stream wrapping the given output stream. | |
47 | static Result<std::shared_ptr<CompressedOutputStream>> Make( | |
48 | util::Codec* codec, const std::shared_ptr<OutputStream>& raw, | |
49 | MemoryPool* pool = default_memory_pool()); | |
50 | ||
51 | // OutputStream interface | |
52 | ||
53 | /// \brief Close the compressed output stream. This implicitly closes the | |
54 | /// underlying raw output stream. | |
55 | Status Close() override; | |
56 | Status Abort() override; | |
57 | bool closed() const override; | |
58 | ||
59 | Result<int64_t> Tell() const override; | |
60 | ||
61 | Status Write(const void* data, int64_t nbytes) override; | |
62 | /// \cond FALSE | |
63 | using Writable::Write; | |
64 | /// \endcond | |
65 | Status Flush() override; | |
66 | ||
67 | /// \brief Return the underlying raw output stream. | |
68 | std::shared_ptr<OutputStream> raw() const; | |
69 | ||
70 | private: | |
71 | ARROW_DISALLOW_COPY_AND_ASSIGN(CompressedOutputStream); | |
72 | ||
73 | CompressedOutputStream() = default; | |
74 | ||
75 | class ARROW_NO_EXPORT Impl; | |
76 | std::unique_ptr<Impl> impl_; | |
77 | }; | |
78 | ||
79 | class ARROW_EXPORT CompressedInputStream | |
80 | : public internal::InputStreamConcurrencyWrapper<CompressedInputStream> { | |
81 | public: | |
82 | ~CompressedInputStream() override; | |
83 | ||
84 | /// \brief Create a compressed input stream wrapping the given input stream. | |
85 | static Result<std::shared_ptr<CompressedInputStream>> Make( | |
86 | util::Codec* codec, const std::shared_ptr<InputStream>& raw, | |
87 | MemoryPool* pool = default_memory_pool()); | |
88 | ||
89 | // InputStream interface | |
90 | ||
91 | bool closed() const override; | |
92 | Result<std::shared_ptr<const KeyValueMetadata>> ReadMetadata() override; | |
93 | Future<std::shared_ptr<const KeyValueMetadata>> ReadMetadataAsync( | |
94 | const IOContext& io_context) override; | |
95 | ||
96 | /// \brief Return the underlying raw input stream. | |
97 | std::shared_ptr<InputStream> raw() const; | |
98 | ||
99 | private: | |
100 | friend InputStreamConcurrencyWrapper<CompressedInputStream>; | |
101 | ARROW_DISALLOW_COPY_AND_ASSIGN(CompressedInputStream); | |
102 | ||
103 | CompressedInputStream() = default; | |
104 | ||
105 | /// \brief Close the compressed input stream. This implicitly closes the | |
106 | /// underlying raw input stream. | |
107 | Status DoClose(); | |
108 | Status DoAbort() override; | |
109 | Result<int64_t> DoTell() const; | |
110 | Result<int64_t> DoRead(int64_t nbytes, void* out); | |
111 | Result<std::shared_ptr<Buffer>> DoRead(int64_t nbytes); | |
112 | ||
113 | class ARROW_NO_EXPORT Impl; | |
114 | std::unique_ptr<Impl> impl_; | |
115 | }; | |
116 | ||
117 | } // namespace io | |
118 | } // namespace arrow |