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 | #ifndef ARROW_IO_COMPRESSED_H |
21 | #define ARROW_IO_COMPRESSED_H |
22 | |
23 | #include <memory> |
24 | #include <string> |
25 | |
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 Status Make(util::Codec* codec, const std::shared_ptr<OutputStream>& raw, |
48 | std::shared_ptr<CompressedOutputStream>* out); |
49 | static Status Make(MemoryPool* pool, util::Codec* codec, |
50 | const std::shared_ptr<OutputStream>& raw, |
51 | std::shared_ptr<CompressedOutputStream>* out); |
52 | |
53 | // OutputStream interface |
54 | |
55 | /// \brief Close the compressed output stream. This implicitly closes the |
56 | /// underlying raw output stream. |
57 | Status Close() override; |
58 | bool closed() const override; |
59 | |
60 | Status Tell(int64_t* position) const override; |
61 | |
62 | Status Write(const void* data, int64_t nbytes) override; |
63 | Status Flush() override; |
64 | |
65 | /// \brief Return the underlying raw output stream. |
66 | std::shared_ptr<OutputStream> raw() const; |
67 | |
68 | private: |
69 | ARROW_DISALLOW_COPY_AND_ASSIGN(CompressedOutputStream); |
70 | |
71 | CompressedOutputStream() = default; |
72 | |
73 | class ARROW_NO_EXPORT Impl; |
74 | std::unique_ptr<Impl> impl_; |
75 | }; |
76 | |
77 | class ARROW_EXPORT CompressedInputStream : public InputStream { |
78 | public: |
79 | ~CompressedInputStream() override; |
80 | |
81 | /// \brief Create a compressed input stream wrapping the given input stream. |
82 | static Status Make(util::Codec* codec, const std::shared_ptr<InputStream>& raw, |
83 | std::shared_ptr<CompressedInputStream>* out); |
84 | static Status Make(MemoryPool* pool, util::Codec* codec, |
85 | const std::shared_ptr<InputStream>& raw, |
86 | std::shared_ptr<CompressedInputStream>* out); |
87 | |
88 | // InputStream interface |
89 | |
90 | /// \brief Close the compressed input stream. This implicitly closes the |
91 | /// underlying raw input stream. |
92 | Status Close() override; |
93 | bool closed() const override; |
94 | |
95 | Status Tell(int64_t* position) const override; |
96 | |
97 | Status Read(int64_t nbytes, int64_t* bytes_read, void* out) override; |
98 | Status Read(int64_t nbytes, std::shared_ptr<Buffer>* out) override; |
99 | |
100 | /// \brief Return the underlying raw input stream. |
101 | std::shared_ptr<InputStream> raw() const; |
102 | |
103 | private: |
104 | ARROW_DISALLOW_COPY_AND_ASSIGN(CompressedInputStream); |
105 | |
106 | CompressedInputStream() = default; |
107 | |
108 | class ARROW_NO_EXPORT Impl; |
109 | std::unique_ptr<Impl> impl_; |
110 | }; |
111 | |
112 | } // namespace io |
113 | } // namespace arrow |
114 | |
115 | #endif // ARROW_IO_COMPRESSED_H |
116 | |